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 ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,a[200005],pre[200005],suf[200005];
int main(){
ios::sync_with_stdio(false);
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int i=1; i<=n; i++){
pre[i] = pre[i - 1];
if(a[i] <= a[i - 1])
pre[i] += a[i - 1] - a[i] + 1;
}
ll ans = 100000000000000;
for(int i=n; i>=1; i--){
suf[i] = suf[i + 1];
if(a[i] <= a[i + 1])
suf[i] += a[i + 1] - a[i] + 1;
ans = min(ans , max(suf[i] , pre[i]));
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |