Submission #1083946

#TimeUsernameProblemLanguageResultExecution timeMemory
1083946JohnnyVenturasKnapsack (NOI18_knapsack)C++17
73 / 100
1036 ms2908 KiB
#include <bits/stdc++.h> using namespace std; struct item { int weight, price, count; }; int main() { int s, n; cin >> s >> n; vector<item> items(n); for (int i = 0; i < n; ++i) { cin >> items[i].price >> items[i].weight >> items[i].count; } vector<int> dp(s + 1, 0); for (int i = 0; i < n; ++i) { for (int x = s; x >= 0; --x) { for (int count = 1; count <= items[i].count; ++count) { if (count * items[i].weight > x) break; dp[x] = max(dp[x], dp[x - count * items[i].weight] + items[i].price * count); } } } cout << dp[s] << "\n"; }
#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...