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;
const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn 210000
ll n, a[maxn], sf[maxn], pf[maxn];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
//freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
cin >> n;
for(ii i = 1; i <= n; i++) {
cin >> a[i];
}
for(ii i = 2; i <= n; i++) {
pf[i] = pf[i-1];
pf[i]+= max(0LL,a[i-1]+1-a[i]);
}
for(ii i = n-1; i >= 1; i--) {
sf[i] = sf[i+1];
sf[i]+= max(0LL,a[i+1]+1-a[i]);
}
ll ans = INFll;
for(ii i = 1; i <= n; i++) {
ans = min(ans, max(sf[i],pf[i]));
//cout << i << " " << pf[i] << " " << sf[i] << endl;
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |