Submission #470663

#TimeUsernameProblemLanguageResultExecution timeMemory
470663DarthspartanKnapsack (NOI18_knapsack)C++17
0 / 100
127 ms262148 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; vector<int> value; vector<int> weight; vector<int> copies; vector<long long> ans (4e4+4,-1); vector<vector<int>> copiesdp(1e5+5, vector<int>(2e3+3)); int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, x; cin >> x >> n; for(int i=0;i<n;i++){ int a,b,c; cin >> a >> b >> c; value.push_back(a); weight.push_back(b); copies.push_back(c); } ans[0]=0; for(int i=0;i<n;i++){ for(int j=0;j<=x;j++){ if(copiesdp[i][j]==copies[i]) continue; if(ans[j+weight[i]]<=ans[j]+value[i]){ ans[j+weight[i]]=ans[j]+value[i]; copiesdp[i][j+weight[i]]=copiesdp[i][j]+1; } } } cout << *(max_element(ans.begin(),ans.begin()+x+1)); 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...