Submission #1023597

#TimeUsernameProblemLanguageResultExecution timeMemory
1023597vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
1 ms344 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int N,S; cin>>N>>S; vector<int> dp(S + 1, 0); for (int i = 0; i < N; ++i) { int V, W, K; cin >> V >> W >> K; for (int qty = 1; K > 0; qty <<= 1) { int actual_qty = min(qty, K); K -= actual_qty; int weight = W * actual_qty; int value = V * actual_qty; for (int w = S; w >= weight; --w) { dp[w] = max(dp[w], dp[w - weight] + value); } } } cout<<dp[S]<<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...