Submission #985656

#TimeUsernameProblemLanguageResultExecution timeMemory
985656vjudge1Knapsack (NOI18_knapsack)C++17
37 / 100
1 ms604 KiB
#include <bits/stdc++.h> using i64 = long long; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int S, N; std::cin >> S >> N; std::vector<int> dp(1 + S); for (int i = 0; i < N; i++) { int v, w, k; std::cin >> v >> w >> k; for (int c = 1; c <= k; c *= 2) { for (int j = S - w * c; j >= 0; j--) { dp[j + w * c] = std::max(dp[j + w * c], dp[j] + v * c); } k -= c; } if (k) { for (int j = S - w * k; j >= 0; j--) { dp[j + w * k] = std::max(dp[j + w * k], dp[j] + v * k); } } } std::cout << dp[S] << "\n"; 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...