CHEFRES: Need a little help with the code

Hi,
This is my code for the chefres problem. I initially sorted the L and R arrays. Later for each test case, I tried to find the greatest L[i] lower than or equal to the given time using a modified binary search. But my solution for subtask 2 is evaluated as “WA”(For subtask 1, it is accepting the solution). I tried to find the issue but am not able. Can anyone kindly find the issue with the code?

https://www.codechef.com/viewsolution/20406821

Thanks,
Sundeep

1 Like

I have used a similar approach you can have a look at my solution.
Solution Link

Thanks for your solution. I am a little new to coding. I can’t exactly understand your solution presently but looks like both methods are similar. Can you please help me find the error in my search function?

I guess that your search function is fine.
Maybe the problem is this: if(p>=max_L)

If p=max_L, the answer should be 0. So, it should be p>max_L.

Thanks a lot aadarsh for pointing out the issue. It worked perfectly after I changed it.

No problem @chenreddy!