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>
#define int long long
#define fastio cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
#define sp <<' '<<
using namespace std;
signed main(){
int n, tmp, ans;
cin >> n;
vector<int> d(n);
vector<int> a(n, 0);
cin >> tmp;
for(int i=1; i<n; i++){
cin >> d[i];
swap(d[i], tmp);
d[i] = tmp-d[i];
}
for(int i=1; i<n; i++){
if(d[i]>0)
a[i] = a[i-1];
else
a[i] = a[i-1]+1-d[i];
}
ans = a[n-1];
tmp = 0;
for(int i=n-1; i>0; i--){
if(d[i]>=0)
tmp += 1+d[i];
ans = min(ans, max(a[i-1], tmp));
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |