Submission #378858

#TimeUsernameProblemLanguageResultExecution timeMemory
378858MounirGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
89 ms5740 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...