Submission #1083951

#TimeUsernameProblemLanguageResultExecution timeMemory
1083951JohnnyVenturasKnapsack (NOI18_knapsack)C++17
29 / 100
1 ms436 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) { int top = min((s - x) / items[i].weight, items[i].count); dp[x + top * items[i].weight] = max(dp[x + top * items[i].weight], dp[x] + items[i].price * top); } } 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...