제출 #976659

#제출 시각아이디문제언어결과실행 시간메모리
976659vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
1064 ms3668 KiB
#include <iostream> using namespace std; struct Kue { long long value, weight, stock; }; int main() { int s, n; cin >> s >> n; Kue kue[n]; long long total_stock = 0; for (int i = 0; i < n; i++) { cin >> kue[i].value >> kue[i].weight >> kue[i].stock; total_stock += 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); for (int j = 1; j <= k; j++) { dp[w] = max(dp[w], dp[w - j * weight] + j * 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...