# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1129146 | idkfr | Knapsack (NOI18_knapsack) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> W >> n;
vector<ll> dp(W + 1, 0);
for (int i = 0; i < n; ++i) {
int wi, vi, ai;
cin >> vi >> wi >> ai;
for (int k = 1; ai > 0; k *= 2) {
int num = min(k, ai);
ai -= num;
int weight = num * wi;
int value = num * vi;
for (int j = W; j >= weight; --j) {
dp[j] = max(dp[j], dp[j - weight] + value);
}
}
}
cout << dp[W] << endl;
return 0;
}