Submission #1067494

#TimeUsernameProblemLanguageResultExecution timeMemory
1067494rohanjhaKnapsack (NOI18_knapsack)C++14
73 / 100
1061 ms7168 KiB
#include<iostream> #include<vector> using namespace std; int main(){ int s, n; cin>>s>>n; vector<vector<int> > items; for(int i=0; i<n; i++){ int v, w, k; cin>>v>>w>>k; vector<int> item; item.push_back(v); item.push_back(w); item.push_back(k); items.push_back(item); } vector<int> dp(s+1, 0); for(int i=0; i<n; i++){ for(int j=s; j>=items[i][1]; j--){ for(int k=1; k<=items[i][2]; k++){ if(j>=k*items[i][1]){ dp[j] = max(dp[j], dp[j-k*items[i][1]]+k*items[i][0]); } else{ break; } } } } std::cout<<dp[s]<<endl; 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...