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>
#define int long long
using namespace std;
const int N = 2e5 + 42, INF = 1e18;
int n, a[N], val[N][2];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 1; i < n; i++)
val[i][0] = val[i-1][0] + max(a[i-1] + 1 - a[i], 0ll);
for(int i = n-2; i > -1; i--)
val[i][1] = val[i+1][1] + max(a[i+1] + 1 - a[i], 0ll);
int ans = INF;
for(int i = 0; i < n; i++)
ans = min(ans, max(val[i][0], val[i][1]));
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |