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 ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 2e5 + 1;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int a[n + 1];
for(int i= 1; i <= n; i++)
cin >> a[i];
ll dp[n + 1], DP[n + 1];
for(int i= 1; i <= n; i++){
if(i == 1) dp[i] = 0;
else{
if(a[i] > a[i - 1]) dp[i] = dp[i - 1];
else dp[i] = dp[i - 1] - a[i] + a[i - 1] + 1;
}
}
for(int i = n; i >= 1; i--){
if(i == n) DP[i] = 0;
else{
if(a[i] > a[i + 1]) DP[i] = DP[i + 1];
else DP[i] = DP[i + 1] - a[i] + a[i + 1] + 1;
}
}
ll ans = 1e18;
for(int i = 1; i <= n; ++i){
ans = min(ans, max(dp[i], DP[i]));
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |