Submission #486898

#TimeUsernameProblemLanguageResultExecution timeMemory
486898YHC2538Knapsack (NOI18_knapsack)C++14
12 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; void _debug(){cerr<<'\n';} template<typename A,typename...B> void _debug(A a,B...b){cerr<<a<<' ',_debug(b...);} #define debug(args...) cerr<<"("<<(#args)<<"): ", _debug(args); #define pii pair<int,int> #define all(x) (x).begin(),(x).end() typedef long long ll; const int N=2005; ll dp[N]; int main(){ int s,n; cin>>s>>n; vector<vector<pii>> weight(s+1); for(int i=1;i<=n;i++){ int v,w,k; cin>>v>>w>>k; weight[w].push_back({v,k}); } for(int i=1;i<=s;i++){ sort(all(weight[i])); if(weight[i].size()==0) continue; int id=0; //next item with weight i for(int j=0;j*i<=s;j++){ if(id>=weight[i].size()) break; for(int k=s;k>=i;k--){ dp[k]=max(dp[k],dp[k-i]+weight[i][id].first); } if(--weight[i][id].second==0) id++; } } cout<<dp[s]<<'\n'; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |             if(id>=weight[i].size()) break;
      |                ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...