This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
int N;
int A[N_MAX + 2];
ll L[N_MAX + 2];
ll R[N_MAX + 2];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> A[i];
}
for (int i = 1; i <= N; i++) {
L[i] = L[i - 1] + max(0, A[i - 1] - A[i] + 1);
}
for (int i = N; i >= 1; i--) {
R[i] = R[i + 1] + max(0, A[i + 1] - A[i] + 1);
}
ll answer = LLONG_MAX;
for (int i = 1; i <= N; i++) {
answer = min(answer, max(L[i], R[i]));
}
cout << answer << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |