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 fi first
#define se second
#define rep(a, b) for(int a = 0; a < (b); a++)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<ll> vl;
const int N=2e5+10;
ll t[N];
void solve(){
int n;
cin>>n;
rep(i,n) cin>>t[i];
ll naj1=0,naj2=0,res=0;
rep(i,n-1) naj1+=max(0LL,t[i+1]-t[i]+1);
res=naj1;
for(int i=1;i<=n-1;i++){
naj1-=max(0LL,t[i]-t[i-1]+1),naj2+=max(0LL,t[i-1]-t[i]+1);
res=min(res,max(naj1,naj2));
}
naj2=0;
for(int i=1;i<n;i++) naj2+=max(0LL,t[i-1]-t[i]+1);
res=min(res,naj2);
cout<<res<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |