Submission #830846

#TimeUsernameProblemLanguageResultExecution timeMemory
830846howard0027Knapsack (NOI18_knapsack)C++14
73 / 100
1080 ms16264 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> V; vector<ll> W; ll T,n,dp[65000]; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>T>>n; for(int i=1;i<=n;++i){ ll v,w,s; cin>>v>>w>>s; for(int j=1;j<=s;j*=2){ V.push_back(j*v); W.push_back(j*w); s-=j; } if(s){ V.push_back(s*v); W.push_back(s*w); } } for(int i=0;i<V.size();i++){ for(int j=T;j-W[i]>=0;j--){ dp[j]=max(dp[j],dp[j-W[i]]+V[i]); } } cout<<dp[T]; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:27:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  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...