Submission #1089549

#TimeUsernameProblemLanguageResultExecution timeMemory
1089549MercubytheFirstKnapsack (NOI18_knapsack)C++17
0 / 100
1093 ms66168 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; #define endl '\n' #ifdef LOCAL #include "debug.h" #else #define debug(...) 37 #endif inline void solve(){ ll S, n; cin >> S >> n; vector<pair<ll, ll> > items; for(ll i = 0; i < n; ++i) { ll val, w, cnt; cin >> val >> w >> cnt; cnt = max(cnt, S); while(cnt--) { items.push_back({val, w}); } } const ll inf = 1e18 + 42; vector<ll> dp(S + 1, -inf); dp[0] = 0; for(auto [item_val, item_w] : items) { for(ll W = S; W >= item_w; --W) { dp[W] = max(dp[W], dp[W - item_w] + item_val); } } cout << *max_element(dp.begin(), dp.end()) << '\n'; } signed main(){ #ifdef LOCAL freopen("test.in", "r", stdin); freopen("err.txt", "w", stderr); #endif ios_base::sync_with_stdio(0); cin.tie(NULL); // signed t; 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...