Submission #965991

#TimeUsernameProblemLanguageResultExecution timeMemory
965991vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
293 ms262144 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int s, n, k, v, w, cw, cv; ll dp[2010], ans; vector<pair<int, int>> item; int main() { cin.tie(0)->sync_with_stdio(0); cin >> s >> n; for(int i=0; i<n; i++) { cin >> v >> w >> k; k = min(k, s/w); while(k--) { item.push_back({w, v}); } } for(auto i: item) { cw = i.first; cv = i.second; for(int j=s; j>=0; j--) { if(dp[j] == 0 && j != 0) continue; if(cw + j <= s) dp[cw+j] = max(dp[cw+j], dp[j]+cv); } } for(int i=0; i<=s; i++) { ans = max(ans, dp[i]); } cout << ans; 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...