Submission #715820

#TimeUsernameProblemLanguageResultExecution timeMemory
715820tengiz05Rabbit Carrot (LMIO19_triusis)C++17
63 / 100
107 ms262144 KiB
#include <bits/stdc++.h>

using i64 = long long;

constexpr int inf = 1001111111;

void chmax(int &a, int b) {
    if (a < b) {
        a = b;
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m;
    std::cin >> n >> m;
    
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    std::vector dp(n + 1, std::vector<int>(n + 1, -inf));
    
    dp[0][0] = 0;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (dp[i][j] == -inf) continue;
            int x = dp[i][j];
            if (a[i] - x <= m) {
                chmax(dp[i + 1][j], a[i]);
            }
            chmax(dp[i + 1][j + 1], x + m);
        }
    }
    
    for (int i = 0; i <= n; i++) {
        if (dp[n][i] != -inf) {
            std::cout << i << "\n";
            return 0;
        }
    }
    assert(false);
    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...