Submission #380222

#TimeUsernameProblemLanguageResultExecution timeMemory
380222peijarGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
28 ms5740 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int nbFleurs; cin >> nbFleurs; vector<int> fleurs(nbFleurs); for (auto &v : fleurs) cin >> v; vector<int> costPrefix(nbFleurs), costSuffix(nbFleurs); costPrefix[0] = 0; for (int iFleurs = 1; iFleurs < nbFleurs; ++iFleurs) { int nbNecessaires = max(0LL, fleurs[iFleurs-1] + 1 - fleurs[iFleurs]); costPrefix[iFleurs] = costPrefix[iFleurs-1] + nbNecessaires; } for (int iFleurs(nbFleurs-2); iFleurs >= 0; --iFleurs) { int nbNecessaires = max(0LL, fleurs[iFleurs+1] + 1 - fleurs[iFleurs]); costSuffix[iFleurs] = costSuffix[iFleurs+1] + nbNecessaires; } int sol(1e18); for (int iMax(0); iMax < nbFleurs; ++iMax) { int cout = max(costPrefix[iMax], costSuffix[iMax]); sol = min(sol, cout); } cout << sol << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...