제출 #1277918

#제출 시각아이디문제언어결과실행 시간메모리
1277918shirokitoKnapsack (NOI18_knapsack)C++20
73 / 100
1096 ms16860 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 24; int n, s; vector<pair<ll, ll>> a; ll dp[N]; void solve() { cin >> s >> n; for (int i = 1; i <= n; i++) { ll v, w, k; cin >> v >> w >> k; ll 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--) { dp[i] = max(dp[i], dp[i - w] + v); } } cout << dp[s] << '\n'; } int main() { cin.tie(0) -> sync_with_stdio(0); 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...