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 <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 200000
lli arr[MAX+2],izq[MAX+2],der[MAX+2];
lli res,a,n;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i,1,n) {
cin >> arr[i];
if(i==1) continue;
der[i] = der[i-1];
if (arr[i] <= arr[i-1]) der[i] += arr[i-1] - arr[i] + 1;
}
res = -1;
repa(i,n,1){
if (i < n) {
izq[i] = izq[i+1];
if (arr[i+1] >= arr[i]) izq[i] += arr[i+1] - arr[i] + 1;
}
a = max(der[i],izq[i]);
if (res == -1 || a < res) res = a;
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |