Submission #1254358

#TimeUsernameProblemLanguageResultExecution timeMemory
1254358labibrafidKnapsack (NOI18_knapsack)C++20
73 / 100
1071 ms456 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll ttt = 1, n, i, k, j, q = 0, m; //cin >> ttt; while(ttt--){ ll wt; cin >> wt >> n; vector<ll> dp(wt + 2, 0); for(i = 0; i < n; ++i){ ll val, w, kk; cin >> val >> w >> kk; for(k = 1; kk > 0; k <<= 1){ ll need = min(kk, k); kk -= need; ll value = val * need, weight = w * need; for(j = wt; j - weight >= 0; --j){ dp[j] = max(dp[j], dp[j - weight] + value); } } } cout << dp[wt]; } } /* 8 3 3 30 1 4 50 1 5 60 1 */
#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...