Need help with Binary Search problem 'PIE' on spoj

Although this problem is tagged with “binary search” but still I am not able to come up with a solution using it. Please help with the underlying concept (solution and any further analysis also,if possible).

Thanks.

Problem link: SPOJ.com - Problem PIE

Look at my solution at M3sFan - Online C++ Compiler & Debugging Tool - Ideone.com

The code is self explanatory.

If you have any doubts, ask in the comment section below.

2 Likes

Thank you so much. It took me some time to understand the application of BS on monotonic function but now I have understood it well.
Thanks once again. :slight_smile: