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<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int main(){
int n;
cin>>n;
vector<ll> old(n+2);
for(int i=0;i<n;i++) cin>>old[i+1];
vector<ll> vec(n+1);
for(int i=0;i<=n;i++) vec[i]=old[i+1]-old[i];
ll pos=0,neg=0;
for(int i=0;i<=n;i++){
if(vec[i]>=0) pos+=vec[i]+1;
}
ll ans=1e18;
for(int i=0;i<n;i++){
if(vec[i]<=0){
neg-=vec[i];
neg++;
}
if(vec[i]>=0){
pos-=vec[i];
pos--;
}
ans=min(ans,max(pos,neg));
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |