# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844747 | qrno | Knapsack (NOI18_knapsack) | C++17 | 1 ms | 388 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
int S, N;
vector<int> V, W;
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> S >> N;
for (int i = 0; i < N; i++) {
int v, w, k;
cin >> v >> w >> k;
int cnt = 1;
for (; cnt <= k; cnt *= 2) {
V.push_back(v * cnt);
W.push_back(w * cnt);
}
if (k & (k+1)) {
cnt = k - cnt/2;
V.push_back(v * cnt);
W.push_back(w * cnt);
}
}
vector<int> most(S+1);
for (int i = 0; i < size(V); i++) {
for (int s = S; s-W[i] >= 0; s--) {
most[s] = max(most[s], most[s-W[i]] + V[i]);
}
}
cout << *max_element(begin(most), end(most)) << endl;
}
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... |