제출 #1129147

#제출 시각아이디문제언어결과실행 시간메모리
1129147idkfrKnapsack (NOI18_knapsack)C++20
37 / 100
1 ms424 KiB
#include<bits/stdc++.h> using namespace std; int main() { int n, W; cin >> W >> n; vector<long long> dp(W + 1, 0); for (int i = 0; i < n; ++i) { int wi, vi, ai; cin >> vi >> wi >> ai; for (int k = 1; ai > 0; k *= 2) { int num = min(k, ai); ai -= num; int weight = num * wi; int value = num * vi; for (int j = W; j >= weight; --j) { dp[j] = max(dp[j], dp[j - weight] + value); } } } cout << dp[W] << endl; 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...