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[0] = 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);
}
}
reverse(a, a + n);
for (int i = 1; i < n; 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, dp[i] + dp1[n - i - 1]);
}
cout << mn;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |