Medium-hard problem on codeforces

problem link-

I don’t have an idea to solve it within the time limit!!! any suggestion?

if we reach at any position by wind in ‘n’ days and the manhattan distance between that position and final position is less than or equal to ‘n’ then we can reach the final position. so we need to find the least value of n but we cant do linearly as it will not fit under the time limit.

Do binary search on days.
Now, this problem boils down to a “Yes-No” problem.(Whether in X days,i can reach or not).
See the editorial for more details.

1 Like