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
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n;cin>>n;
vector <int> a(n+1);
for(int i=1;i<=n;i++)cin>>a[i];
a.pb(0);
int mn=1e18;
vector <int> cnt(n+1);
for(int i=1;i<=n;i++){
vector <int> v=a;
for(int j=1;j<=i;j++){
v[j]=max(v[j-1]+1,v[j]);
cnt[j]=v[j]-a[j];
}
for(int j=n;j>=i;j--){
v[j]=max(v[j+1]+1,v[j]);
cnt[j]=v[j]-a[j];
}
int ans=0;
int l=1,r=n;
while(l<=r){
int x=min(cnt[l],cnt[r]);
ans+=x;
cnt[l]-=x;
if(r!=l)cnt[r]-=x;
if(!cnt[l])l++;
if(!cnt[r])r--;
}
mn=min(mn,ans);
}
cout<<mn<<"\n";
}
/*
5
3 2 2 3 1
5
9 7 5 3 1
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |