#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |