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>
using namespace std;
const int MAXN = 2e5 + 123;
int a[MAXN];
signed main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = n - 1; i > 0; --i)
a[i] -= a[i - 1];
int ans = 0;
int val = 0;
for (int i = 1; i < n; ++i)
val += max(0, a[i] + 1);
ans = val;
for (int i = 1; i < n; ++i) {
val -= max(0, a[i] + 1);
val += max(0, -a[i] + 1);
ans = min(ans, val);
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |