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 <bits/stdc++.h>
#define ft first
#define sd second
#define pb push_back
#define nl "\n"
#define int ll
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 1000100;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
while(T--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int dp[n], dp1[n];
dp[0] = 0;
dp1[n - 1] = 0;
for (int i = 1; i < n; i++) {
dp[i] = dp[i - 1];
if (a[i - 1] >= a[i]) {
dp[i] += (a[i - 1] - a[i] + 1);
}
}
for (int i = n - 2; i >= 0; i--) {
dp1[i] = dp1[i + 1];
if (a[i + 1] >= a[i]) {
dp1[i] += (a[i + 1] - a[i] + 1);
}
}
int mn = 1e18;
for (int i = 0; i < n; i++) {
mn = min( mn, max(dp[i], dp1[i]));
}
cout << mn;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |