# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
923747 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 69 ms | 37452 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;
#define ll long long
int const N = 2002;
vector<pair<ll, int>> I[N];
vector<ll> W[N];
ll dp[N][N];
int S, n;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> S >> n;
for (int i = 0; i < n; ++i) {
ll v; int w, k; cin >> v >> w >> k;
I[w].emplace_back(-v, k);
}
for (int i = 1; i < N; ++i) {
sort(I[i].begin(), I[i].end());
W[i].push_back(0);
for (auto& [v, k]: I[i]) {
for (int j = 0; j < k; ++j) {
W[i].push_back(W[i].back() - v);
if (W[i].size() * i - i > S) break;
}
}
I[i].clear();
}
for (int w = 1; w <= S; ++w) {
for (int s = S; s >= 0; --s) {
for (int c = 0; c < W[w].size() && c*w <= s; ++c) {
dp[w][s] = max(dp[w][s], W[w][c] + dp[w-1][s - c*w]);
}
}
}
cout << dp[S][S] << '\n';
}
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... |