제출 #1112862

#제출 시각아이디문제언어결과실행 시간메모리
1112862slyceloteRabbit Carrot (LMIO19_triusis)C++17
0 / 100
1 ms592 KiB
#include <algorithm>
#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main() {
    cin.tie(0); iostream::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    const ll NEGINF = -1 - (n+1)*m;

    vector<ll> a(n+2);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] -= i*m;
    }
    a[n+1] = NEGINF;

    vector<int> dp(n+2);
    for (int i = n; i >= 0; --i) {
        int j = i+1;
        while (a[j] > a[i])
            ++j;
        dp[i] = dp[j] + j - i - 1;

        ll maxval = NEGINF;
        for (int j = i+1; j <= n+1; ++j) {
            if (maxval < a[j] && a[j] <= a[i]) {
                dp[i] = min(dp[i], dp[j] + j - i - 1);
            }
            maxval = max(maxval, a[j]);
        }

    }

    cout << dp[0] << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...