You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can binary search the number of operations required to make the array non-decreasing.
2
+
3
+
We can make A[i] = (A[i], A[i] + x) (mod M).
4
+
5
+
These are the reachable values for A[i].
6
+
7
+
We will choose the smallest value possible at each step for each A[i], while maintaining the condition that A[i] is not smaller than the prefix minimum.
8
+
9
+
If possible we will make A[i] = the prefix minimum. Otherwise, we will make the minimum = A[i].
10
+
11
+
If A[i] can't be made >= minimum and is < minimum, then it is not possible in x moves.
12
+
13
+
---
14
+
15
+
At each step, we are making the minimum as small as possible. It is never optimal to increase some previous element by more than what we have as that would increase the minimum.
16
+
17
+
---
18
+
19
+
int possible(int operations, int m, vector <int> &A)
0 commit comments