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 rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debugsl(a) cout << #a << " = " << a << ", "
#define debug(a) cout << #a << " = " << a << endl
#define MAX 200000
lli n,a,res;
lli arr[MAX+2];
lli pref[MAX+2],suf[MAX+2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i,1,n) cin >> arr[i];
//prefijo
rep(i,2,n) {
if (arr[i-1] >= arr[i]) pref[i] = arr[i-1] - arr[i] + 1;
pref[i] += pref[i-1];
}
//prefijo
repa(i,n-1,1) {
if (arr[i+1] >= arr[i]) suf[i] = arr[i+1] - arr[i] + 1;
suf[i] += suf[i+1];
}
res = 1ll<<62;
rep(i,1,n) {
a = max(pref[i], suf[i]);
res = min(res,a);
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |