제출 #844779

#제출 시각아이디문제언어결과실행 시간메모리
844779qrnoKnapsack (NOI18_knapsack)C++17
100 / 100
44 ms4952 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int S, N; cin >> S >> N; vector<vector<pair<int, int>>> W(S+1); for (int i = 0; i < N; i++) { int v, w, k; cin >> v >> w >> k; W[w].push_back({v, k}); } vector<int> M(S+1); for (int w = 1; w <= S; w++) { sort(rbegin(W[w]), rend(W[w])); int left = S/w; for (auto [v, k] : W[w]) { while (left && k) { for (int i = S; i-w >= 0; i--) M[i] = max(M[i], M[i-w]+v); k--, left--; } if (!left) break; } } cout << *max_element(begin(M), end(M)) << endl; }
#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...