#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int s, n;
cin >> s >> n;
vector<int> v(n), w(n), k(n);
for (int i = 0; i < n; i++) {
cin >> v[i] >> w[i] >> k[i];
}
vector<vector<int>> best(n + 1, vector<int>(s + 1));
for (int p = 0; p < n; p++) {
for (int W = 0; W <= s; W++) {
best[p + 1][W] = max(best[p + 1][W], best[p][W]);
for (int K = 1; K <= k[p] && W + K * w[p] <= s; K++) {
best[p + 1][W + K * w[p]] = max(best[p + 1][W + K * w[p]], best[p][W] + K * v[p]);
}
}
}
cout << best[n][s] << '\n';
return 0;
}
| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |