제출 #1016884

#제출 시각아이디문제언어결과실행 시간메모리
1016884thinknoexitKnapsack (NOI18_knapsack)C++17
100 / 100
42 ms2908 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int v[100100], w[100100], k[100100]; int dp[2020]; vector<pair<int, int>> vec[2020]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int s, n; cin >> s >> n; for (int i = 1;i <= n;i++) { cin >> v[i] >> w[i] >> k[i]; k[i] = min(k[i], s / w[i]); vec[w[i]].push_back({ v[i], k[i] }); } for (int i = 1;i <= s;i++) { sort(vec[i].rbegin(), vec[i].rend()); int cnt = s / i; int now = 0; for (auto& x : vec[i]) { while (x.second-- && ++now <= cnt) { for (int j = 2000;j >= i;j--) { dp[j] = max(dp[j], dp[j - i] + x.first); } } if (now > cnt) break; } } cout << (*max_element(dp, dp + s + 1)); 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...