# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
654552 | pauloamed | Knapsack (NOI18_knapsack) | C++14 | 128 ms | 5324 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
const int MAXN = 2010;
vector<pair<int,int>> W0[MAXN];
vector<pair<int,int>> v;
int K[MAXN];
int32_t main(){
int S, n; cin >> S >> n;
for(int i = 0; i < n; ++i){
int v, w, k; cin >> v >> w >> k;
W0[w].push_back({v, k});
}
for(int w = 1; w <= S; ++w){
vector<int> tmp;
sort(W0[w].rbegin(), W0[w].rend());
for(auto &[x, k] : W0[w]){
while(tmp.size() <= ((S+w-1)/w) && k--){
tmp.push_back(x);
}
}
for(auto x : tmp) v.push_back({x, w});
}
// cout << v.size() << "\n";
int ans = 0;
for(auto [x, w] : v){
for(int i = S - w; i >= 0; --i){
K[i + w] = max(K[i + w], K[i] + x);
ans = max(ans, K[i + w]);
}
}
cout << ans << "\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... |