This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mxsz = 2e5 + 10;
const int inf = 1e9 + 7;
int n, a[mxsz], p[mxsz], s[mxsz], mn=inf;
int main () {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
p[i] = p[i-1] + max(0, 1 - (a[i] - a[i-1]));
}
for (int i = n-1; i >= 1; i--) {
s[i] = s[i+1] + max(0, (a[i+1] - a[i]) + 1);
}
for (int i = 1; i <= n; i++) {
mn = min(mn, max(p[i], s[i]));
}
cout << mn;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |