Submission #975008

#TimeUsernameProblemLanguageResultExecution timeMemory
975008vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
119 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int s,n; vector<pair<int,int> > weight[2005]; vector<pair<int,int> > item; int dp[20005][2005]; int cek(int idx,int brt){ if(brt<0)return -1e15; if(idx==item.size())return 0; int &res=dp[idx][brt]; if(res!=-1)return res; //item[idx]; res=max(cek(idx+1,brt),cek(idx+1,brt-item[idx].first)+item[idx].second); return res; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>s>>n; for(int r=1;r<=n;r++){ int v,w,k; cin>>v>>w>>k; weight[w].push_back({v,k}); } for(int d=1;d<=2000;d++){ sort(weight[d].begin(),weight[d].end()); int maks= 2000/d +1; while(maks>0 && !weight[d].empty()){ maks--; item.push_back({d,weight[d].back().first}); weight[d].back().second--; if(weight[d].back().second==0){ weight[d].pop_back(); } } } memset(dp,-1,sizeof dp); cout<<cek(0,s); }

Compilation message (stderr)

knapsack.cpp: In function 'long long int cek(long long int, long long int)':
knapsack.cpp:12:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     if(idx==item.size())return 0;
      |        ~~~^~~~~~~~~~~~~
#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...