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 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |