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>
using namespace std;
#define int long long
int n,a[200005],d[200005];
int pref[200005],suf[200005];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i < n; i++)
d[i] = a[i + 1] - a[i];
for (int i = 1; i < n; i++)
pref[i] = pref[i - 1] + max(-d[i] + 1,0ll);
for (int i = n - 1; i >= 1; i--)
suf[i] = suf[i + 1] + max(d[i] + 1,0ll);
int ans = 1e18;
for (int k = 1; k <= n; k++)
ans = min(ans,max(pref[k - 1],suf[k]));
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |