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: http://www.spoj.com/problems/PIE/

Look at my solution at http://ideone.com/M3sFan

The code is self explanatory.

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

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: