제출 #1259850

#제출 시각아이디문제언어결과실행 시간메모리
1259850tareqKnapsack (NOI18_knapsack)C++20
37 / 100
1 ms328 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int S, N; cin >> S >> N; vector<pair<int,int>> items; for (int i = 0; i < N; i++) { int V, W, K; cin >> V >> W >> K; int power = 1; while (K > 0) { int take = min(power, K); items.push_back({W * take, V * take}); K -= take; power <<= 1; } } vector<int> dp(S+1, 0); for (auto [w, v] : items) { for (int cap = S; cap >= w; cap--) { dp[cap] = max(dp[cap], dp[cap - w] + v); } } cout << dp[S] << "\n"; return 0; }
#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...