제출 #1174361

#제출 시각아이디문제언어결과실행 시간메모리
1174361Hamed_GhaffariGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
23 ms2632 KiB
#include<bits/stdc++.h>
using namespace std;

const int MXN = 2e5+5;

int n, a[MXN];
long long dp[MXN];

int32_t main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
        dp[i] = dp[i-1] + (a[i-1]>=a[i] ? a[i-1]-a[i]+1 : 0);
    }
    long long ans = 1e18, val=0;
    for(int i=n; i>=1; i--) {
        val += (a[i+1]>=a[i] ? a[i+1]-a[i]+1 : 0);
        ans = min(ans, max(dp[i], val));
    }
    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...