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 <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin >> n;
vector <ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll uk = 0;
vector <ll> potl(n);
for (int i = 0; i < n - 1; i++){
potl[i] = uk;
ll tren = a[i] + 1 - a[i+1];
if (tren > 0)
uk += tren;
}
potl[n-1] = uk;
uk = 0;
ll rjes = potl[n-1];
for (int i = n - 1; i >= 1; i--){
ll tren = a[i] + 1 - a[i-1];
if (tren > 0)
uk += tren;
rjes = min(rjes, max(uk, potl[i-1]));
}
cout << rjes;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |