제출 #967539

#제출 시각아이디문제언어결과실행 시간메모리
967539stdfloatKnapsack (NOI18_knapsack)C++17
73 / 100
1051 ms1500 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int S, n; cin >> S >> n; vector<vector<pair<int, int>>> u(S + 1); while (n--) { int v, w, k; cin >> v >> w >> k; u[w].push_back({v, k}); } vector<ll> dp(S + 1, -1); dp[0] = 0; for (int w = 1; w <= S; w++) { sort(u[w].rbegin(), u[w].rend()); int s = S / w; for (auto [v, k] : u[w]) { int mn = min(s, k); while (mn--) { for (int j = S; j >= w; j--) if (dp[j - w] != -1) dp[j] = max(dp[j], dp[j - w] + v); } s -= mn; if (!s) break; } } cout << *max_element(dp.begin(), dp.end()); }
#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...