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 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
signed main(){
fastio
int n;
cin >> n;
int arr[n], diff[n], pref[n] = {}, suff[n+1] = {};
for(auto &x : arr) cin >> x;
for(int i = 1;i < n;i++){
diff[i] = arr[i] - arr[i-1];
}
int ans = 1e18;
for(int i = 1;i < n;i++){
pref[i] = (pref[i-1] + (diff[i] < 1 ? 1-diff[i] : 0));
}
for(int i = n-1;i >= 0;i--){
suff[i] = (suff[i+1] + (diff[i] > -1 ? diff[i]+1 : 0));
}
for(int i = 0;i < n;i++){
ans = min(ans,max(pref[i],suff[i+1]));
}
cout << ans << "\n";
}
//-10 32 51 -81 87 -62 56
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |