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<queue>
using namespace std;
int const N = 2005;
typedef long long LL;
LL const inf = 1e18;
LL a[N], dif[N];
LL suf[N];
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
dif[i] = a[i] - a[i - 1];
}
for(int i = n; i > 0; i--){
suf[i] = suf[i + 1];
if(dif[i] >= 0){
suf[i] += dif[i] + 1;
}
}
LL ans = inf, pre = 0;
for(int i = 1; i <= n; i++){
if(dif[i] <= 0){
pre += (-dif[i]) + 1;
}
ans = min(ans, max(pre, suf[i + 1]));
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |