제출 #679130

#제출 시각아이디문제언어결과실행 시간메모리
679130Ronin13Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
31 ms6104 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...