Need help with the question

I used binary search in my code I am trying to get the maximum distance up to which we do not any issue in allocating, here is the link to the code. Submission #89284370 - Codeforces