Submission #924981

#TimeUsernameProblemLanguageResultExecution timeMemory
924981doducanhKnapsack (NOI18_knapsack)C++14
100 / 100
91 ms2168 KiB
#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)

knapsack.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:20: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]
   20 |             if(id>=a[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...