제출 #750349

#제출 시각아이디문제언어결과실행 시간메모리
750349nguyenneheheKnapsack (NOI18_knapsack)C++14
37 / 100
1 ms468 KiB
#include<bits/stdc++.h> using namespace std; signed main() { cin.tie(nullptr)->sync_with_stdio(false); int s, n; cin >> s >> n; vector<pair<int, int>> a; for (int i = 1; i <= n; ++i) { int v, w, k; cin >> v >> w >> k; int pw = 1; while (pw <= k) { k -= pw; a.emplace_back(w * pw, v * pw); pw <<= 1; } if (k > 0) a.emplace_back(w * k, v * k); } vector<long long> dp(s + 1); for (pair<int, int> p: a) { for (int w = s; w >= p.first; --w) { dp[w] = max(dp[w], dp[w - p.first] + p.second); } } 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...