×

# Can anyone help me with Pro Chef And Katana from LoC June 2018 ?

 1 Hello friends can someone tell me how to approach this problem ? I am getting WA. Here is my latest submission. If it's too messy, here is the approach I used : n =readInt() arr = readInts() count = 0 for i in range(len(arr)): count+=1 f =0 minus = arr[i] for j in range(len(arr)): arr[j]-=minus for j in range(len(arr)): if arr[j]>0: f =1 if f==0: break print(count)  asked 09 Jul, 07:54 278●1●10 accept rate: 1% At least make sure arr[i] > 0 before subtracting it from the whole array. (09 Jul, 08:36)

 1 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: 2 2 1  Your code gives 1 as answer, but you need atleast 2 cuts. answered 09 Jul, 08:33 915●1●15 accept rate: 35% n =readInt() arr = readInts() count = 0 for i in range(len(arr)): count+=1 f =0 minus = arr[i] if minus <0: continue for j in range(i,len(arr)): arr[j]-=minus for j in range(i,len(arr)): if arr[j]>0: f =1 if f==0: break  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)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,583
×2,227
×135
×66