#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> pref(n + 1, 0);
vector<int> suf(n + 1, 0);
for(int i = 1; i <= n; i++) {
pref[i] = pref[i - 1] + max(a[i - 1] - a[i] + 1, 0LL);
}
for(int i = n - 1; i >= 0; i--) {
suf[i] = suf[i + 1] + max(a[i + 1] - a[i] + 1, 0LL);
}
int ans = 1e18;
for(int i = 1; i <= n; i++) {
ans = min(ans, max(pref[i], suf[i]));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |