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
#define pii pair<int, int>
vector<int> dp[2];
signed main(){
int n;
cin>>n;
vector<int>v(n);
for(int i = 0; i<n; i++){
cin>>v[i];
}
for(int i = 0; i<2; i++){
dp[i].resize(n);
dp[i][0] = 0;
for(int j = 1; j<n; j++){
dp[i][j] = dp[i][j-1];
if(v[j]<=v[j-1]){
dp[i][j] += v[j-1]-v[j]+1;
}
}
reverse(v.begin(), v.end());
}
reverse(dp[1].begin(), dp[1].end());
int res= 1e18;
for(int i = 0; i<n; i++){
//cout<<dp[0][i]<<" "<<dp[1][i]<<endl;
res = min(res, max(dp[0][i], dp[1][i]));
}
cout<<res<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |