Fake binary search

The link of the problem is : Contest Page | CodeChef
I have written this code : Solution: 55935718 | CodeChef
It is giving wrong answer in just 3 test cases of small subtasks, I am not able to find the case where it fails, please help me out :slightly_frowning_face: