Submission #1082949

#TimeUsernameProblemLanguageResultExecution timeMemory
1082949Kiet07Knapsack (NOI18_knapsack)C++14
100 / 100
72 ms35152 KiB
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("TEST.inp","r",stdin); map<int,vector<pair<int,int>>>mp; int limit,n; cin>>limit>>n; for(int i=1;i<=n;i++) { int v,w,k; cin>>v>>w>>k; mp[w].push_back({v,k}); } vector<vector<long long>>dp(mp.size()+1,vector<long long>(limit+1,0)); int i=1; for(auto it:mp) { sort(it.second.begin(),it.second.end(),greater<pair<int,int>>()); for(int j=1;j<=limit;j++) { dp[i][j]=dp[i-1][j]; long long profit=0; int cur_i=0,cnt=0,copy=0; while((copy+1)*it.first<=j&&cur_i<it.second.size()) { copy++; profit+=it.second[cur_i].first; cnt++; dp[i][j]=max(dp[i][j],dp[i-1][j-copy*it.first]+profit); if(cnt==it.second[cur_i].second) { cur_i++; cnt=0; } } } i++; } cout<<dp[mp.size()][limit]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:24:37: 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 |    while((copy+1)*it.first<=j&&cur_i<it.second.size())
      |                                ~~~~~^~~~~~~~~~~~~~~~~
#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...