Hello friends can someone tell me how to approach this problem ? I am getting WA. @vijju123 @taran_1407 @vivek_1998299 @meooow @john_smith_3 @aryanc403 @vbt_95 Here is my latest submission. If it's too messy, here is the approach I used :
asked 09 Jul, 07:54

You'll need to subtract the MINIMUM element of the segment from each element of the segment. By segment I mean, a contiguous range, surrounded by a 0 at both sides. Eg. 1, 4, 7, 0, 4, 0, 7, 8 has three segments; 1 is minimum of the first segment, 4 of the second and 7 of the third segment. Try the simple test:
Your code gives 1 as answer, but you need atleast 2 cuts. answered 09 Jul, 08:33
n =readInt() arr = readInts() count = 0 for i in range(len(arr)):
print(count) @sarthakmanna here is the approach where am I missing. Also for 100 points I feel it's too slow.
(09 Jul, 11:15)
1
I was trying to explain this approach: https://www.codechef.com/viewsolution/19150087 For 100pts, you can use a stack or priority queue like this: https://www.codechef.com/viewsolution/19011529 The 100pt solution is written in Java. I hope you'll have no problem in understanding it. However, if you have any, feel free to ask.
(10 Jul, 00:43)
thanks man I got it now. Let me code it out using stack :)
(10 Jul, 06:07)

At least make sure arr[i] > 0 before subtracting it from the whole array.