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;
#define int long long
int32_t main() {
int n; cin >> n;
vector<int> a(n); for(auto &e : a) cin >> e;
vector<int> dpl(n), dpr(n);
for(int i = 0; i < n; i++) {
if(i == 0) dpl[i] = 0;
else {
if(a[i] > a[i - 1]) dpl[i] = dpl[i - 1];
else dpl[i] = dpl[i - 1] + (a[i - 1] + 1 - a[i]);
}
}
for(int i = n - 1; i >= 0; i--) {
if(i == n - 1) dpr[i] = 0;
else {
if(a[i] > a[i + 1]) dpr[i] = dpr[i + 1];
else dpr[i] = dpr[i + 1] + (a[i + 1] + 1 - a[i]);
}
}
int ans = (1LL << 50);
for(int i = 0; i < n; i++) {
ans = min(ans, max(dpl[i], dpr[i]));
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |