# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1136403 | tsengang | Knapsack (NOI18_knapsack) | C++20 | 1097 ms | 16796 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define ertunt return
int main() {
ll s, n;
scanf("%lld %lld", &s, &n);
vector<pair<ll, ll>> items;
for (ll i = 0; i < n; i++) {
ll v, w, k;
scanf("%lld %lld %lld", &v, &w, &k);
for (ll j = 1; k > 0; j <<= 1) {
ll take = min(j, k);
items.pb({v * take, w * take});
k -= take;
}
}
vector<ll> dp(s + 1, 0);
for (auto [v, w] : items) {
for (ll j = s; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
printf("%lld", dp[s]);
ertunt 0;
}
Compilation message (stderr)
# | 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... |