제출 #1277924

#제출 시각아이디문제언어결과실행 시간메모리
1277924shirokitoKnapsack (NOI18_knapsack)C++20
73 / 100
430 ms327680 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2000 + 24; int n, s; vector<int> W[N]; int dp[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--) W[w].push_back(v); } for (int w = 1; w <= s; w++) { sort(W[w].rbegin(), W[w].rend()); } for (int w = 1; w <= s; w++) { for (int v: W[w]) { for (int i = s; i >= w; i--) { dp[i] = max(dp[i], dp[i - w] + 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...