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 ll long long
#define int ll
#define pii pair<int,int>
#define X first
#define Y second
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define abs(x) ((x)>0?(x):-(x))
#define pb push_back
int a[200010],b[200010];
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
F(n)cin>>a[i];
F(n-1)b[i]=a[i+1]-a[i];
int s0=0,s1=0;
F(n-1)if(b[i]>=0)s1+=(b[i]+1);
int an=1e18;
an=min(an,max(s0,s1));
//F(n-1)cout<<b[i]<<" ";
//cout<<endl;
F(n-1){
if(b[i]>0){
s1-=(b[i]+1);
}
else if(b[i]==0){
s1--;
s0++;
}
else{
s0-=(b[i]-1);
}
an=min(an,max(s0,s1));
}
cout<<an<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |