제출 #1277975

#제출 시각아이디문제언어결과실행 시간메모리
1277975shirokitoKnapsack (NOI18_knapsack)C++20
12 / 100
2 ms572 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2000 + 24; int n, s; priority_queue<int> S[N]; int dp[N]; vector<int> V[N]; void solve() { cin >> s >> n; for (int i = 1; i <= n; i++) { int v, w, k; cin >> v >> w >> k; k = min(k, s / w); while (k--) { S[w].push(v); if ((int) S[w].size() > s / w) { S[w].pop(); } } } for (int w = 1; w <= s; w++) { while (S[w].size()) { V[w].push_back(S[w].top()); S[w].pop(); } } for (int w = 1; w <= s; w++) { for (int i = s; i >= w; i--) { int k = 0, v = 0; for (int x: V[w]) { k++; v += x; if (i - w * k < 0) break; dp[i] = max(dp[i], dp[i - w * k] + v); } } } cout << dp[s] << '\n'; } int main() { cin.tie(nullptr) -> sync_with_stdio(false); int T = 1; // cin >> T; while (T--) { solve(); } }
#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...