Submission #1041358

#TimeUsernameProblemLanguageResultExecution timeMemory
1041358daviolimenKnapsack (NOI18_knapsack)C++17
73 / 100
1056 ms18148 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct item { ll v, w; }; int S, N; ll dp[2001]; item arr[33000000]; int main() { cin >> S >> N; ll ctr = 0; for (int i = 0; i < N; i++) { ll v, w, k; cin >> v >> w >> k; ll c = 1; while (c < k) { k -= c; arr[++ctr].v = v * c; arr[ctr].w = w * c; c *= 2; } arr[++ctr].v = v * k; arr[ctr].w = w * k; } for (int i = 1; i <= ctr; i++) { for (int j = S; j >= arr[i].w; j--) { dp[j] = max(dp[j], dp[j - arr[i].w] + arr[i].v); } } cout << dp[S] << "\n"; }
#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...