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
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<int> arr(N);
for(int i = 0;i<N;++i) cin >> arr[i];
vector<int> pref(N),suf(N); pref[0] = 0;
for(int i = 1;i<N;++i){
pref[i] = pref[i-1]+max(arr[i-1]-arr[i]+1,(int)0);
}
suf[N-1] = 0;
for(int i = N-2;i>=0;--i){
suf[i] = suf[i+1]+max(arr[i+1]-arr[i]+1,(int)0);
}
int ans = (int)(1e18);
for(int i = 0;i<N;++i){
//cout << suf[i] << " " << pref[i] << "\n";
ans = min(ans,max(suf[i],pref[i]));
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |