#include <bits/stdc++.h>
using namespace std;
// 2 ^ 10 ~= 10 ^ 3 => 2 ^ 30 > 10 ^ 9
const int MAX_N = 1e5, MAX_S = 2e3, MAX_K = 1e9, MAX_K_BIT = 30;
int v[MAX_N + 1], wi[MAX_N + 1], k[MAX_N + 1];
vector<pair<int, int>> items;
int dp[MAX_S + 1];
signed main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int s, n, i, j, w, new_w, put2;
cin >> s >> n;
for (i = 1; i <= n; i++) {
cin >> v[i] >> wi[i] >> k[i];
put2 = 1;
while (k[i] > 0) {
k[i] -= put2;
items.push_back(make_pair(wi[i] * put2, v[i] * put2));
put2 = min(2 * put2, k[i]);
}
}
// bounded
for (auto [item_w, item_v] : items) {
// cout << "[" << item_w << ", " << item_v << "]\n";
for (w = s; w >= 0; w--) {
new_w = w + item_w;
if (new_w <= s) {
dp[new_w] = max(dp[new_w], dp[w] + item_v);
}
}
}
cout << dp[s];
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... |