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;
#define int long long
#define ld long double
#define ar array
const int INF = 1e17;
const int MOD = 998244353;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie();
int n; cin>>n;
vector<int> a(n); for (int &i : a) cin>>i;
vector<int> pf(n, 0), sf(n, 0);
for (int i = 1; i < n; i++) pf[i] = pf[i-1] + max(a[i-1]-a[i]+1, 0LL);
for (int i = n-2; i >= 0; i--) sf[i] = sf[i+1] + max(a[i+1]-a[i]+1, 0LL);
int ans = INF;
for (int i = 0; i < n; i++) {
// keep pairing stuff on left and right and [l,r]++
ans = min(ans,max(pf[i], sf[i]));
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |