제출 #1166701

#제출 시각아이디문제언어결과실행 시간메모리
1166701tamyteRabbit Carrot (LMIO19_triusis)C++20
14 / 100
98 ms98376 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//    #ifndef ONLINE_JUDGE
//    ifstream cin("input.txt");
//    #endif // ONLINE_JUDGE
    int N, M;

    cin >> N >> M;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    vector<vector<int>> dp(N + 1, vector<int>(5001, N + 1));
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= 5000; ++j) {
            if (a[i] - j <= M) {
                dp[i + 1][a[i]] = min(dp[i + 1][a[i]], dp[i][j]);
            }
            if (j + M <= 5000) {
                dp[i + 1][j + M] = min(dp[i + 1][j + M], dp[i][j] + 1);
            }
        }
    }
    int res = N;
    for (int i = 0; i <= 5000; ++i) {
        res = min(res, dp[N][i]);
    }
    cout << res << 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...