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 pb push_back
#define double long double
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int32_t main(){
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin>>n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin>>a[i];
}
vector<int> dp1(n+1), dp2(n+1);
dp1[1] = 0;
for(int i = 1; i < n; i++){
dp1[i+1] = dp1[i] + max(0LL, a[i-1] + 1 - a[i]);
}
dp2[n] = 0;
for(int i = n-2; i >= 0; i--){
dp2[i+1] = dp2[i+2] + max(0LL, a[i+1] + 1 - a[i]);
}
int ans = mod * mod;
for(int i = 1; i <= n; i++){
ans = min(ans, max(dp1[i], dp2[i]));
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |