# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
924981 | doducanh | Knapsack (NOI18_knapsack) | C++14 | 91 ms | 2168 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;
vector<pair<int,int>>a[2005];
int dp[2005];
int s,n;
main()
{
cin>>s>>n;
for(int i=1;i<=n;i++){
int v,w,k;
cin>>v>>w>>k;
a[w].push_back({v,k});
}
memset(dp,0,sizeof(dp));
for(int i=0;i<=s;i++){
if(!a[i].size())continue;
sort(a[i].begin(),a[i].end(),greater<pair<int,int>>());
int id=0;
for(int j=0;j*i<s;j++){
if(id>=a[i].size())break;
for(int k=s;k>=i;k--){
dp[k]=max(dp[k],dp[k-i]+a[i][id].first);
}
a[i][id].second--;
if(a[i][id].second==0)id++;
}
}
cout<<dp[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... |