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>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
signed main(){
int nVals; cin >> nVals;
vector<int> vals(nVals), gauche(nVals), droite(nVals);
for (int& val : vals)
cin >> val;
gauche[0] = 0; droite[nVals - 1] = 0;
for (int ind = 1; ind < nVals; ++ind)
gauche[ind] = gauche[ind - 1] + max(0ll, vals[ind - 1] - vals[ind] + 1);
for (int ind = nVals - 2; ind >= 0; --ind)
droite[ind] = droite[ind + 1] + max(0ll, vals[ind + 1] - vals[ind] + 1);
/*
for (int ind = 0; ind < nVals; ++ind) cout << gauche[ind] << " ";
cout << endl;
for (int ind = 0; ind < nVals; ++ind) cout << droite[ind] << " ";
cout << endl;*/
int mini = min(gauche[nVals - 1], droite[0]);
for (int coupe = 0; coupe < nVals - 1; ++coupe)
chmin(mini, max(gauche[coupe], droite[coupe + 1]) + ((vals[coupe] + gauche[coupe]) == (vals[coupe + 1] + droite[coupe + 1])));
cout << mini << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |