Submission #1046579

#TimeUsernameProblemLanguageResultExecution timeMemory
1046579NewtonabcKnapsack (NOI18_knapsack)C++14
37 / 100
1 ms440 KiB
#include<bits/stdc++.h> using namespace std; const int N=2e3+10; vector<pair<int,int> > v; int dp[N]; int main(){ int s,n; cin>>s >>n; while(n--){ int a,b,c; cin>>a >>b >>c; int tmp=1; while(c>=tmp){ v.push_back(make_pair(a*tmp,b*tmp)); c-=tmp; tmp*=2; } v.push_back(make_pair(a*c,b*c)); } for(int i=0;i<v.size();i++){ int val=v[i].first,wg=v[i].second; for(int j=s;j>=1;j--){ if(j-wg>=0) dp[j]=max(dp[j],dp[j-wg]+val); } } cout<<dp[s]; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:20:15: 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 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
#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...