Submission #976652

#TimeUsernameProblemLanguageResultExecution timeMemory
976652vjudge1Knapsack (NOI18_knapsack)C++17
29 / 100
2 ms348 KiB
#include <iostream> using namespace std; struct Kue { long long value, weight, stock; }; int main() { int s, n; cin >> s >> n; Kue kue[n]; for (int i = 0; i < n; i++) { cin >> kue[i].value >> kue[i].weight >> kue[i].stock; } long long dp[s + 1] = {0}; int k = 0; for (int i = 0; i < n; i++) { for (int w = s; w >= 0; w--) { auto [val, weight, stock] = kue[i]; if (weight > w) break; k = min(w / weight, stock); dp[w] = max(dp[w], dp[w - k * weight] + k * val); } } cout << dp[s]; }
#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...