#include<bits/stdc++.h>
typedef int ll;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl '\n'
#define TASK ""
#define N 800005
#define LOG 17
using namespace std;
ll n, a[N], pf[N], sf[N];
signed main() {
   // freopen("test.inp", "r", stdin);
	//freopen("test.out", "w", stdout);
	//srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
   	cin >> n;
   	for (int i = 1; i <= n; i ++) {
   		cin >> a[i];
   	}
   	for (int i = 2; i <= n; i ++) {
   		pf[i] = pf[i - 1] + max(0, a[i - 1] + 1 - a[i]);
   	}
   	for (int i = n - 1; i >= 1; i --) {
   		sf[i] = sf[i + 1] + max(0, a[i + 1] - a[i] + 1);
   	}
   	ll ans = 1e9;
   	for (int i = 1; i <= n; i ++) {
   		ans = min(ans, max(pf[i], sf[i]));
   	}
   	cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |