# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
540568 | ac2hu | Knapsack (NOI18_knapsack) | C++14 | 4 ms | 340 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>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int s,n;cin >> s >> n;
int ll = ceil(log2(s));
vector<array<int,3>> iitems(n);
vector<array<int,3>> items;
for(int i = 0;i<n;i++){
for(int j = 0;j<3;j++)cin >> iitems[i][j];
iitems[i][2] = min(iitems[i][2], s);
int lg = log2(iitems[i][2]);
for(int mask =0;mask<=lg;mask++){
items.push_back({iitems[i][0]*(1 << mask), iitems[i][1]*(1 << mask), 1});
}
}
vector<int> old((int)2e3 + 10), ne((int)2e3 + 10);
for(int i = 0;i<items.size();i++){
swap(old, ne);
for(int j = 1;j<=s;j++){
ne[j] = max(old[j], ne[j - 1]);
if(j >= items[i][1])
ne[j] = max(ne[j], old[j - items[i][1]] + items[i][0]);
}
}
cout << ne[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... |