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;
int main()
{
int n;
cin >> n;
int r[n-1];
int64_t pr[n];
int o;
cin >> o;
pr[0] = 0;
for(int i = 1;i < n;++i)
{
int x;
cin >> x;
r[i-1] = x-o;
pr[i] = pr[i-1] + max(0,1-r[i-1]);
o = x;
}
int64_t ans = 1e18;
int64_t sf = 0;
for(int i = n-1;i >= 0;--i)
{
ans = min(ans,max(pr[i],sf));
sf += (i == 0 ? 0 : max(0,r[i-1]+1));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |