REPLESX - understand WA

Hello,

I want to understand why I am guetting wrong answer on REPLESX

Here is the code : https://www.codechef.com/viewsolution/38817320

I have been able to have AC , just by replacing binary Search logic with while loop :
https://www.codechef.com/viewsolution/38818642

But I cannot figure out what was wrong with the binary Search method.

Thanks for your advices