# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1104182 | micro7 | Knapsack (NOI18_knapsack) | C++17 | 82 ms | 7240 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 <algorithm>
#include <cstdio>
#include <functional>
#include <map>
using namespace std;
constexpr int MAXS = 2000;
int n, s;
map<int, map<int, int, greater<>>> m;
int dp[MAXS + 1];
int main() {
scanf("%d%d", &s, &n);
for (int i = 0; i < n; ++i) {
int v, w, k;
scanf("%d%d%d", &v, &w, &k);
m[w][v] += k;
}
for (auto &[w, v_cnt] : m) {
for (int i = s; i >= w; --i) {
int prv_w = i, profit = 0;
for (auto [v, k] : v_cnt) {
while (prv_w >= w && k) {
prv_w -= w;
profit += v;
dp[i] = max(dp[i], dp[prv_w] + profit);
--k;
}
if (prv_w < w)
break;
}
}
}
printf("%d", dp[s]);
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... |