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;
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);
}
int main(){
cin >> n;
for(int i = 0,tmp; i < n; i++){
cin >> tmp;
arr.push_back(tmp);
}
/*int x;
for(int j = 0; j < 100;j++){
cin >> x;
cout << check(x) << endl;
}*/
int l = 0, r = n-1,mid,a,b;
while(1){
if(r-l <= 4){
break;
}
mid = (l+r)/2;
a = check(mid);
b = check(mid+1);
if(a < b){
r = mid-1;
}
else{
l = mid+1;
}
}
int ans = 1e9;
for(int i = l; i <= r; 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... |