이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |