#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const uint64_t len = 3000;
uint64_t dp[len] = {0};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, s;
cin >> s >> n;
vector<uint64_t> price(n), weight(n), count(n);
for (int i = 0; i < n; ++i) {
cin >> price[i] >> weight[i] >> count[i];
}
uint64_t ans = 0;
for (int idx = 0; idx < n; ++idx) {
for (int cnt = 1; cnt <= min(count[idx], s / weight[idx]); ++cnt) {
for (int total_w = s; total_w >= weight[idx]; --total_w) {
dp[total_w] = max(dp[total_w], dp[total_w - weight[idx]] + price[idx]);
ans = max(ans, dp[total_w]);
}
}
}
cout << ans;
}
| # | 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... |