# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
970983 | handlename | Knapsack (NOI18_knapsack) | C++17 | 44 ms | 3160 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;
int s,n;
int memo[2001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>s>>n;
multiset<int> arr[s+1];
for (int i=0;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
c=min(c,s/b);
while (c>0 && arr[b].size()+1<=s/b){
arr[b].insert(a);
c--;
}
while (c>0 && a>(*arr[b].begin())){
arr[b].erase(arr[b].begin());
arr[b].insert(a);
c--;
}
}
for (int b=0;b<=s;b++){
for (auto a:arr[b]){
for (int j=s-b;j>=0;j--){
memo[j+b]=max(memo[j+b],memo[j]+a);
}
}
}
cout<<memo[s];
}
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... |