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 <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
const int N = 2e5 + 2, mod = 1e9 + 7;
const long long inf = 1e18 + 49;
int n;
int a[N];
long long dp[N], rdp[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = dp[i - 1];
if (a[i] <= a[i - 1])
dp[i] += a[i - 1] + 1 - a[i];
}
rdp[n] = 0;
for (int i = n - 1; i >= 1; i--) {
rdp[i] = rdp[i + 1];
if (a[i] <= a[i + 1])
rdp[i] += a[i + 1] + 1 - a[i];
}
long long ans = inf;
for (int i = 1; i <= n; i++) {
ans = min(ans, max(dp[i], rdp[i]));
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |