제출 #1277978

#제출 시각아이디문제언어결과실행 시간메모리
1277978shirokitoKnapsack (NOI18_knapsack)C++20
73 / 100
4 ms584 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2000 + 24; int n, s; int v[N], w[N], k[N]; int dp[N]; vector<int> V[N]; void solve() { cin >> s >> n; for (int i = 1; i <= n; i++) { cin >> v[i] >> w[i] >> k[i]; } vector<int> id; for (int i = 1; i <= n; i++) { id.push_back(i); } sort(id.begin(), id.end(), [&] (int i, int j) { return v[i] > v[j]; }); for (int i: id) { int sz = s / w[i]; while ((int) V[w[i]].size() < sz && k[i]) { V[w[i]].push_back(v[i]); k[i]--; } } 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...