#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], f[N], g[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) f[i] = f[i - 1] + max(0, a[i - 1] - a[i] + 1);
for (int i = n; i; i--) g[i] = g[i + 1] + max(0, a[i + 1] - a[i] + 1);
int res = 2e9;
for (int i = 1; i <= n; i++) {
res = min(res, max(f[i], g[i]));
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |