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 int long long
#define IO ios::sync_with_stdio(0), cin.tie(0);
#define FOR(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
using pii = pair<int, int>;
void dbg() {;}
template<class T, class ...U>
void dbg(T a, U ...b) { cout << a << " "; dbg(b...); }
void ent() { cout << "\n"; }
const int INF = 1e16;
const int N = 200005;
int a[N], b[N];
int dx[2][N];
signed main() {
IO;
int n;
cin >> n;
FOR(i, 1, n) cin >> a[i];
FOR(i, 2, n) b[i] = a[i] - a[i - 1];
FOR(i, 2, n) {
if (b[i] <= 0)
dx[0][i] = 1 - b[i];
if (b[i] >= 0)
dx[1][i] = b[i] - (- 1);
dx[0][i] += dx[0][i - 1];
dx[1][i] += dx[1][i - 1];
}
int ans = INF;
FOR(i, 1, n) {
int pre = dx[0][i];
int suf = dx[1][n] - dx[1][i];
ans = min(ans, max(pre, suf));
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |