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;
typedef long long ll;
ll n, ans = 1e18, a[200005], ps[200005], ss[200005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 2; i <= n; i++) {
ps[i] = ps[i-1] + max(a[i-1] - a[i] + 1, 0ll);
}
for (int i = n-1; i >= 1; i--) {
ss[i] = ss[i+1] + max(a[i+1] - a[i] + 1, 0ll);
}
for (int i = 1; i <= n; i++) {
ans = min(ans, max(ps[i], ss[i]));
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |