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<queue>
#include<set>
#include<map>
#include<iomanip>
#include<math.h>
#include<cstring>
#include<stack>
#include<string.h>
#include<random>
#include<algorithm>
#include<vector>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define INF (ll)(8e18)
#define pb push_back
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
ll b[200005],a[200005],pre[200005],suf[200005];
signed main(){
AC;
int n; cin>>n;
FOR(i,1,n+1) cin>>a[i];
FOR(i,2,n+1){
b[i]=a[i]-a[i-1];
}
FOR(i,2,n+1){
pre[i]=pre[i-1];
if(b[i]<=0) pre[i]+=(1-b[i]);
}
REP(i,n,2){
suf[i]=suf[i+1];
if(b[i]>=0) suf[i]+=(b[i]+1);
}
ll ans=pre[n];
FOR(i,2,n+2){
if(pre[i-1]>=suf[i]){
ans=min(ans,pre[i-1]);
}
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |