제출 #704070

#제출 시각아이디문제언어결과실행 시간메모리
704070StickfishGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms316 KiB
#include <iostream>
using namespace std;

const int MAXN = 2e5 + 123;
int a[MAXN];

signed main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = n - 1; i > 0; --i)
        a[i] -= a[i - 1];
    int ans = 0;
    int val = 0;
    for (int i = 1; i < n; ++i)
        val += max(0, a[i] + 1);
    ans = val;
    for (int i = 1; i < n; ++i) {
        val -= max(0, a[i] + 1);
        val += max(0, -a[i] + 1);
        ans = min(ans, val);
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...