#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<int> dp(s + 1, INT_MIN);
dp[0] = 0;
for (int i = 0; i < n; i++) {
int v, w, k;
cin >> v >> w >> k;
for (int p = 1; k > 0; p <<= 1) {
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;
}
}
int ans = *max_element(dp.begin(), dp.end());
cout << (ans == INT_MIN ? 0 : ans) << endl;
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... |