Need help with the question

https://codeforces.com/contest/1393/problem/C
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. https://codeforces.com/contest/1393/submission/89284370