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
vector<int> arr;
int n;
int check(int idx){
vector<int> akr = arr;
int a = 0,b = 0;
for(int i = 1; i <= idx; i++){
if(akr[i-1] >= akr[i]){
a += akr[i-1]+1-akr[i];
}
}
for(int i = n-1; i > idx; i--){
if(akr[i-1] <= akr[i]){
b += akr[i]+1-akr[i-1];
}
}
return max(a,b);
}
signed main(){
cin >> n;
for(int i = 0,tmp; i < n; i++){
cin >> tmp;
arr.push_back(tmp);
}
int ans = 1e18;
for(int i = 0; i < n;i++){
ans = min(ans,check(i));
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |