Codeforces 1169C. Increasing by Modulo Codeforces 1168A. Increasing by Modulo


Problem link

Problem link

Let's check that the answer to the problem is ≤x.

Then, for each element, you have some interval (interval on the "circle" of remainders modulo m) of values, that it can be equal to.

So you need to check that you can pick in each interval some point, to make all these values non-decrease.

You can do it with greedy! Each time, let's take the smallest element from the interval, that is at least the previously chosen value.

And after this, let's make the binary search on x.

So we have the solution in O(nlogm).

A solution in c++


Post a Comment

0 Comments