Submission #981133

#TimeUsernameProblemLanguageResultExecution timeMemory
981133aaaaaarrozKnapsack (NOI18_knapsack)C++17
37 / 100
116 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,w; cin>>w>>n; vector<int>valores; vector<int>pesos; for(int i=0;i<n;i++){ int v,w,k; cin>>v>>w>>k; for(int j=0;j<k;j++){ valores.push_back(v); pesos.push_back(w); } } vector<vector<int>>dp(valores.size(),vector<int>(w+1,0)); for(int i=0;i<=w;i++){ if(pesos[0]<=i)dp[0][i]=valores[0]; else dp[0][i]=0; } for(int i=1;i<valores.size();i++){ for(int j=0;j<=w;j++){ dp[i][j]=dp[i-1][j]; if(pesos[i]<=j){ dp[i][j]=max(dp[i-1][j],valores[i]+dp[i-1][j-pesos[i]]); } } } cout<<dp[valores.size()-1][w]<<"\n"; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=1;i<valores.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...