Submission #1023586

#TimeUsernameProblemLanguageResultExecution timeMemory
1023586vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
1 ms348 KiB
#include <iostream> #include <vector> #include <algorithm> #include <climits> 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 j = 1; K > 0; j <<= 1) { int qty = min(j, K); K -= qty; int weight = W * qty; int value = V * qty; for (int w = S; w >= weight; --w) { dp[w] = max(dp[w], dp[w - weight] + value); } } } int max_value = *max_element(dp.begin(), dp.end()); cout << max_value << 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...