제출 #986992

#제출 시각아이디문제언어결과실행 시간메모리
986992vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
49 ms2908 KiB
#include <bits/stdc++.h> using i64 = long long; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int m, n; std::cin >> m >> n; std::vector item(1 + m, std::vector<std::tuple<int, int>>()); for (int i = 0; i < n; i++) { int v, w, k; std::cin >> v >> w >> k; item[w].push_back({v, k}); } std::vector<int> dp(1 + m); for (int w = 1; w <= m; w++) { std::sort(item[w].begin(), item[w].end(), std::greater<std::tuple<int, int>>()); for (int j = m; j >= 0; j--) { [&]() { int val = 0, wt = 0; for (auto [v, k] : item[w]) { for (int c = 0; c < k; c++) { val += v, wt += w; if (j + wt > m) { return; } dp[j + wt] = std::max(dp[j + wt], dp[j] + val); } } }(); } } std::cout << dp[m] << "\n"; 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...