I am getting TLE in my solution for pumping water . After seeing other solutions, I found that people are using similar approach to me. I am unable to know the reason why my code is getting TLE.
After adding one condition it is getting correct answer.
Well, when you are querying for a segment say [l,r] and if the maximum position lies in index r or l, then your function should return 1 as the most highest value is present in the extreme ends of the array.
But your function is recurring for more subproblems increasing the overall complexity of the program.
For the test case
1
4
1 2 3 10
instead of going through only [0,3]
your function is computing for
[0 3]
[0 2]
[3 2]
[0 1]
[2 1]
[0 0]
[1 0]
hence increasing the complexity of the program.
modification of code to get ac->
https://www.codechef.com/viewsolution/21144046
2 Likes