제출 #967530

#제출 시각아이디문제언어결과실행 시간메모리
967530stdfloatKnapsack (NOI18_knapsack)C++17
73 / 100
231 ms262144 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; map<int, vector<pair<int, int>>> m; for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; m[w].push_back({-v, k}); } vector<ll> V, W; for (auto w : m) { int s = S / w.first; for (auto [v, k] : w.second) { int mn = min(s, k); while (mn--) { V.push_back(-v); W.push_back(w.first); } s -= mn; } } vector<ll> dp(S + 1, -1); dp[0] = 0; for (int i = 0; i < (int)V.size(); i++) { for (int j = S; j >= W[i]; j--) if (dp[j - W[i]] != -1) dp[j] = max(dp[j], dp[j - W[i]] + V[i]); } 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...