#include <algorithm>
#include <iostream>
using namespace std;
const int N = 200000;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
int aa[N];
long long pp[N], qq[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n; cin >> n;
for (int i = 0; i < n; i++)
cin >> aa[i];
long long p = 0;
for (int i = 1; i < n; i++)
pp[i] = p += max(aa[i - 1] + 1 - aa[i], 0);
long long q = 0;
for (int i = n - 2; i >= 0; i--)
qq[i] = q += max(aa[i + 1] + 1 - aa[i], 0);
long long ans = INF;
for (int i = 0; i < n; i++)
ans = min(ans, max(pp[i], qq[i]));
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |