# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844775 | qrno | Knapsack (NOI18_knapsack) | C++14 | 1086 ms | 18892 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 int long long
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int S, N;
cin >> S >> N;
vector<pair<int, int>> A;
for (int i = 0; i < N; i++) {
int v, w, k;
cin >> v >> w >> k;
for (int cnt = 1; cnt <= k; cnt *= 2) {
A.push_back({v*cnt, w*cnt});
k -= cnt;
}
A.push_back({v*k, w*k});
}
vector<int> most(S+1);
for (auto [v, w] : A) {
for (int s = S; s-w >= 0; s--) {
most[s] = max(most[s], most[s-w] + v);
}
}
cout << *max_element(begin(most), end(most)) << '\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... |