#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 2e5 + 7;
const ll inf = 1e18 + 7;
ll a[mxN], sum[mxN];
int n;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum[i] = sum[i - 1];
if (a[i] <= a[i - 1])
sum[i] += a[i - 1] + 1 - a[i];
}
ll cur = 0, ans = inf;
for (int i = n; i >= 1; i--)
{
if (a[i] <= a[i + 1])
cur += a[i + 1] + 1 - a[i];
ans = min(ans, max(cur, sum[i]));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |