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;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N;
cin>>N;
ll arr[N];
for(ll i = 0;i < N;i++){
cin>>arr[i];
}
ll ans = 1e18;
ll prefix[N];
ll Ldiff = 0;
for(ll i = 0;i < N;i++){
if(i >= 1) Ldiff += max(0ll,(arr[i - 1] + 1) - arr[i]);
prefix[i] = Ldiff;
}
ll suffix[N];
ll Rdiff = 0;
for(ll i = N - 1;i >= 0;i--){
if(i < N - 1) Rdiff += max(0ll,(arr[i + 1] + 1) - arr[i]);
suffix[i] = Rdiff;
}
for(ll split = 0;split < N;split++){
ll total = max(prefix[split],suffix[split]);
ans = min(ans,total);
}
cout<<ans<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |