#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int S, N;
cin >> S >> N;
vector<int> dp(S + 1, 0);
for (int i = 0; i < N; i++) {
int v, w, k;
cin >> v >> w >> k;
vector<int> items;
for (int j = 1; k > 0; j *= 2) {
int take = min(j, k);
items.push_back(take);
k -= take;
}
for (int take : items) {
for (int j = S; j >= take * w; j--) {
dp[j] = max(dp[j], dp[j - take * w] + take * v);
}
}
}
cout << *max_element(dp.begin(), dp.end()) << "\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... |