제출 #731799

#제출 시각아이디문제언어결과실행 시간메모리
731799manhtuan22007Knapsack (NOI18_knapsack)C++14
73 / 100
1089 ms17648 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; int n , s; ll dp[2005]; vector<pair<ll , ll>> a; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for(int i = 1 ;i <= n ; i ++){ ll v , w , k; cin >> v >> w >> k; ll x = 1; while(k >= x){ a.push_back({x * v , x * w}); k -= x; x *= 2; } if(k) a.push_back({k * v , k * w}); } for(pair<ll , ll> i : a){ for(int j = s ; j >= i.second ; j --){ dp[j] = max(dp[j - i.second] + i.first , dp[j]); } } cout << dp[s]; }
#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...