#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int s, n;
cin >> s >> n;
vector<pair<int, int>> items[2001];
for(int i = 0; i < n; i++) {
int v, w, k;
cin >> v >> w >> k;
if(w <= s) items[w].push_back({v, k});
}
vector<int> dp(s + 1, INT_MIN);
dp[0] = 0;
for(int w = 1; w <= s; w++) {
for(auto [v, k] : items[w]) {
for(int p = 1; k > 0; p *= 2) {
int take = min(p, k);
for(int j = s; j >= w * take; j--) {
if(dp[j - w * take] != INT_MIN) {
dp[j] = max(dp[j], dp[j - w * take] + v * take);
}
}
k -= take;
}
}
}
cout << max(0, *max_element(dp.begin(), dp.end())) << 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |