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;
signed main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin>>n;
vector<int>x,y; x.push_back(0);
int a[n]; for(auto &i:a) cin>>i;
for(int i=0;i<n-1;i++) x.push_back(max(0ll,a[i]-a[i+1]+1));
for(int i=0;i<n-1;i++) y.push_back(max(0ll,a[i+1]-a[i]+1));
y.push_back(0);
for(int i=1;i<n;i++) x[i]+=x[i-1];
for(int i=n-2;i>=0;i--) y[i]+=y[i+1];
int ans=1e18;
for(int i=0;i<n;i++) ans=min(ans,x[i]+y[i]);
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |