제출 #807340

#제출 시각아이디문제언어결과실행 시간메모리
807340caganyanmazGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
82 ms5368 KiB
#include <bits/stdc++.h>
#define int int64_t
using namespace std;

constexpr static int INF = 1e17;
constexpr static int MXSIZE = 3e5;

int n, v[MXSIZE], dp[MXSIZE+1][2]; // Increasing, decreasing

int32_t main()
{
        cin >> n;
        for (int i = 0; i < n; i++)
                cin >> v[i];
        for (int i = 2; i <= n; i++)
                dp[i][0] = dp[i-1][0] + max<int>(0, 1 + v[i-2] - v[i-1]);
        for (int i = n-2; i >= 0; i--)
                dp[i][1] = dp[i+1][1] + max<int>(0, 1 + v[i+1] - v[i]);
        int mn = INF;
        for (int i = 0; i < n; i++)
                mn = min(mn, max(dp[i+1][0], dp[i][1]));
        cout << mn << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...