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 int long long
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int arr[n+1];
for(int i=1;i<=n;i++){
cin >> arr[i];
}
int dp1[n+1];
int dp2[n+1];
dp1[1]=0;
for(int i=2;i<=n;i++){
dp1[i]=dp1[i-1];
if(arr[i]<=arr[i-1]){
dp1[i]+=arr[i-1]-arr[i]+1;
}
}
dp2[n]=0;
for(int i=n-1;i>=1;i--){
dp2[i]=dp2[i+1];
if(arr[i]<=arr[i+1]){
dp2[i]+=arr[i+1]-arr[i]+1;
}
}
int ans=max(dp1[1],dp2[1]);
for(int i=2;i<=n;i++){
ans=min(ans,max(dp1[i],dp2[i]));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |