#include <bits/stdc++.h>
using namespace std;
#define int long long int
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n), r(n, 0); for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 1; i < n; i++) r[n-i-1] = max(0LL, (a[n-i] + 1) - (a[n-i-1])) + r[n-i];
int t = 4e18, f = 0; for (int i = 1; i < n; i++) f += max(0LL, (a[i-1] + 1) - a[i]), t = min(t, max(r[i], f));
cout << t << "\n";
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |