# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
964403 | KasymK | Knapsack (NOI18_knapsack) | C++17 | 1048 ms | 2756 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
int S, n;
scanf("%d%d", &S, &n);
vector<int> v(n), w(n), k(n);
for (int i = 0; i < n; ++i)
scanf("%d%d%d", &v[i], &w[i], &k[i]);
vector<long long> dp(S + 1);
for (int i = 0; i < n; ++i)
for (int j = S; j >= w[i]; --j){
int mn = min(j / w[i], k[i]);
for (int cnt = 1; cnt <= mn; cnt++)
dp[j] = max(dp[j], dp[j - cnt * w[i]] + cnt * v[i]);
}
long long ans = *max_element(dp.begin(), dp.end());
printf("%lld\n", ans);
return 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... |