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;
typedef long long ll;
const ll N = 2e5;
const ll inf = 1e18;
ll v[N],v2[N],v3[N];
int main(){
ll n;
ll ans = inf;
cin>>n;
for(ll i = 0;i < n;i++){
cin>>v[i];
}
for(ll i = 1;i < n;i++){
v2[i] = v2[i - 1] + max(0ll,v[i - 1] - v[i] + 1);
}
for(ll i = n - 2;i >= 0;i--){
v3[i] = v3[i + 1] + max(0ll,v[i + 1] - v[i] + 1);
}
for(ll i = 0;i < n;i++){
ans = min(ans,max(v2[i],v3[i]));
}
cout<<ans<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |