제출 #1020953

#제출 시각아이디문제언어결과실행 시간메모리
1020953urejgiKnapsack (NOI18_knapsack)C++17
73 / 100
1072 ms16304 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; vector<int> values, weights; for(int i = 0; i < n; ++i){ int v, w, k; cin >> v >> w >> k; int count = 1; while(k > 0){ int curcnt = min(count, k); values.push_back(curcnt*v); weights.push_back(curcnt*w); k -= curcnt; count <<= 1; } } int items_cnt = values.size(); vector<int> dp(s+1, 0); for(int i = 0; i < items_cnt; ++i){ for(int j = s; j >= weights[i]; --j){ dp[j] = max(dp[j], dp[j - weights[i]] + values[i]); } } cout << dp[s]; 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...