Painter's parttiton problem wrong output

https://hack.codingblocks.com/contests/c/512/716
https://ide.codingblocks.com/s/41784
can you please tell me what’s wrong with my code.

Test Case Number Result
#1 wrong-answer
#2 wrong-answer
#3 wrong-answer
#4 Time Limit Exceeded
#5 wrong-answer
#6 wrong-answer

Your code is wrong. You did not understand the problem statement completely.
It is mentioned in question that
Every painter can paint only contiguous segments of boards.
A board can only be painted by 1 painter at maximum.

So you cannot sort the array as you are doing in your code. If you sort then you can’t get answers for continuous segments of boards as demanded in question. Your code gives wrong answer even on the sample test case.

Read the question again carefully and then attempt it again.
Hint: Think of Binary Search.

1 Like