# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
871110 | tvladm2009 | Knapsack (NOI18_knapsack) | C++17 | 55 ms | 4184 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 i64 = long long;
std::vector<std::pair<int, int>> a[2005];
int dp[2005];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int s, n;
std::cin >> s >> n;
for (int i = 1; i <= n; i++) {
int v, w, k;
std::cin >> v >> w >> k;
a[w].emplace_back(std::make_pair(v, k));
}
std::vector<int> val, w;
for (int step = 1; step <= 2000; step++) {
std::sort(a[step].rbegin(), a[step].rend());
int lim = s / step;
for (int j = 0; j < a[step].size() && lim > 0; j++) {
for (int j2 = 1; j2 <= a[step][j].second && lim > 0; j2++) {
val.emplace_back(a[step][j].first);
w.emplace_back(step);
lim--;
}
}
}
for (int i = 0; i < val.size(); i++) {
for (int j = s; j >= w[i]; j--) {
dp[j] = std::max(dp[j], dp[j - w[i]] + val[i]);
}
}
std::cout << dp[s] << "\n";
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... |