제출 #1136402

#제출 시각아이디문제언어결과실행 시간메모리
1136402tsengangKnapsack (NOI18_knapsack)C++20
73 / 100
1096 ms16796 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(x) (x).begin(), (x).end() #define ertunt return int main() { ll s, n; cin >> s >> n; vector<pair<ll, ll>> items; for (ll i = 0; i < n; i++) { ll v, w, k; cin >> v >> w >> k; for (ll j = 1; k > 0; j <<= 1) { ll take = min(j, k); items.pb({v * take, w * take}); k -= take; } } vector<ll> dp(s + 1, 0); for (auto [v, w] : items) { for (ll j = s; j >= w; j--) { dp[j] = max(dp[j], dp[j - w] + v); } } cout << dp[s]; ertunt 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...