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 dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
const int N=1e6+99,inf=1e18;
int n,t,ans=inf,a[N],res1[N],res2[N],mx1[N],mx2[N];
main(){
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n;
f(i,1,n+1){
cin>>a[i];
}
mx1[1]=a[1];
mx2[n]=a[n];
f(i,2,n+1){
mx1[i]=max(a[i],mx1[i-1]+1);
res1[i]=res1[i-1]+max(0ll,a[i-1]+1-a[i]);
}
f_(i,n-1,1){
mx2[i]=max(a[i],mx2[i+1]+1);
res2[i]=res2[i+1]+max(0ll,a[i+1]+1-a[i]);
//cout<<i<<" -> "<<mx2[i]<<" "<<res2[i]<<endl;
}
f(i,1,n+1) minm(ans,max(res1[i],res2[i]));
cout<<ans;
}
Compilation message (stderr)
Main.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
28 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |