Getting a TLE for snakeeat Problem(binary search).

Hello, Here is the problem link For the Snakeeat Problem. But I am getting a TLE
for my submission.
Here is the link for my solution.
Any reviews will helpful.

//