제출 #1277923

#제출 시각아이디문제언어결과실행 시간메모리
1277923shirokitoKnapsack (NOI18_knapsack)C++20
73 / 100
1096 ms8552 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 24; int n, s; vector<pair<int, int>> a; int dp[N]; void maximize(int &A, int B) { if (A < B) A = B; } 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); int p = 1; while (k) { if (k >= p) { a.push_back({w * p, v * p}); k -= p; p *= 2; } else { a.push_back({w * k, v * k}); k = 0; } } } for (auto [w, v]: a) { for (int i = s; i >= w; i--) { maximize(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...