Chopsticks Problem, I am getting a W.A.

This is the problem statement:-

My solution for it:-
https://www.codechef.com/viewsolution/19763718

Can someone please provide me with a test case which fails in my code? OR any mistake in the code?

1 Like

Hi, in your code in the chop function, with the while loop you have written if( (a[i]-a[i-1]) <= 2). You need to make the 2 to d, i.e. if( (a[i]-a[i-1]) <= d).

This type of mistakes happen as a beginner no issue. But I would like to suggest you to look into this code. Just take a look and see how you can avoid writing the merge-sort function and do it efficiently with the inbuilt library function in C++. Just take a look here :- https://www.codechef.com/viewsolution/18047823

I am sure you would not like to spend time coding up a sorting function in C while others will use a inbuilt function. :slight_smile:

Hope this helps. :smiley: