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
int n;
vector<int> ml;
vector<int> generate_ml(){
vector<int> fin;
for(int i=0; i<n; i++){
fin.push_back(ml[i]);
}
return fin;
}
int focus(vector<int> &ai_list, int focus){
int total = 0;
vector<int> b = {focus, focus};
while((b[0] > 0) && (ai_list[b[0]-1] < ai_list[b[0]])){
b[0]--;
}
while((b[1] < n-1) && (ai_list[b[1]] > ai_list[b[1]+1])){
b[1]++;
}
while(b[0]!=0 || b[1]!=n-1){
int left_side, right_side;
if (b[0] == 0){
left_side = 100000000000000;
}
else {
left_side = ai_list[b[0]-1] - ai_list[b[0]];
}
if (b[1] == n-1){
right_side = 100000000000000;
}
else{
right_side = ai_list[b[1]+1] - ai_list[b[1]];
}
int amount = min(left_side, right_side)+1;
total+=amount;
ai_list[b[0]] += amount;
ai_list[b[1]] += amount;
while((b[0] > 0) && (ai_list[b[0]-1] < ai_list[b[0]])){
b[0]--;
}
while((b[1] < n-1) && (ai_list[b[1]] > ai_list[b[1]+1])){
b[1]++;
}
}
return total;
}
signed main(){
cin>>n;
for (int i=0; i<n; i++) {
int x; cin>>x;
ml.push_back(x);
}
vector<int> main_list = generate_ml();
int mn = focus(main_list, 0);
for(int i=0; i<n; i++){
main_list = generate_ml();
int cnt = focus(main_list, i);
if (cnt < mn) mn = cnt;
}
cout<<mn<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |