#include <bits/stdc++.h>
using namespace std;
int sir[200002];
int64_t necesar[200001];
int main ()
{
ios :: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int lungime;
cin >> lungime;
for (int indice = 1 , actual , anterior = -1 ; indice <= lungime ; indice++)
{
cin >> actual;
sir[indice] = actual - anterior;
anterior = actual;
}
sir[lungime + 1] = -1;
for (int indice = 1 ; indice <= lungime ; indice++)
{ necesar[indice] = necesar[indice - 1] + max(0 , 1 - sir[indice]); }
int64_t rezultat = INT64_MAX , termen = 0;
for (int indice = lungime + 1 ; indice ; indice--)
{
termen += max(0 , sir[indice] + 1);
rezultat = min(rezultat , max(termen , necesar[indice - 1]));
}
cout << rezultat;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |