Need help in CHEFRES

Hi,
I would like to know what is wrong with my solution for CHEFRES. I am getting a partial correct solution and a TLE for the second subtask.

My solution: https://www.codechef.com/viewsolution/20401498

The editoral of the CHEFRES had been submitted by user few minutes ago.You can check that solution and find error in your question.

I saw the editorial and couldn’t identify the error. Hence, please help me out. :slight_smile:

The complexity of your code is O(NlogN + MN). It will easily give a TLE as M, N <=10^5. Try to use binary search as the sorted intervals, being non-intersecting form a monotonic function and hence justify the use of Binary Search {O((N+M)logN)}

Thanks Kshitij!! :slight_smile: