제출 #1127673

#제출 시각아이디문제언어결과실행 시간메모리
1127673heisenbergKnapsack (NOI18_knapsack)C++20
37 / 100
1097 ms58016 KiB
#include<bits/stdc++.h> using namespace std ; long long knapsack(vector<long long> weights , vector<long long> & prices , long long W) { int N = weights.size() ; vector<long long> dp(W + 1,0) ; for(int i = N - 1 ; i >= 0 ; --i) { for(int cap = W ; cap >= weights[i] ; --cap) { dp[cap] = max(dp[cap],prices[i] + dp[cap - weights[i]]) ; } } return dp[W] ; } void run_case() { long long S , N ; cin >> S >> N ; vector<long long> weights , prices ; for(int i = 0 ; i < N ; ++i) { long long value , weight , k = 0 ; cin >> value >> weight >> k ; while(k--) { weights.push_back(weight) ; prices.push_back(value) ; } } cout << knapsack(weights,prices,S) ; } signed main() { run_case() ; 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...