Rainwater harvesting problem

PLease check my code as it doesnt work.
problem link : https://hack.codingblocks.com/contests/c/512/512
My solution: https://ide.codingblocks.com/s/34720
thanks.

Your approach is wrong.
Your code doesn’t work even for the given sample case

Try to maintain an array which contains max of left starting from first position

And another array which stores max of right starting from the rightmost position.

Then take min of the two arrays as only that amount of water can be stored. And sum all these values to get answer.