Submission #1119746

#TimeUsernameProblemLanguageResultExecution timeMemory
1119746vjudge1Knapsack (NOI18_knapsack)C++17
37 / 100
2 ms596 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; void solve() { int s, t; cin >> s >> t; vector<pii> items; // {weight, value} while (t--) { int v, w, k; cin >> v >> w >> k; if (w > s) continue; // Ignore items that can't fit even once for (int i = 1; i <= k; i *= 2) { items.push_back({w * i, v * i}); k -= i; } if (k > 0) { items.push_back({w * k, v * k}); } } vector<int> dp(s + 1, 0); for (auto &[weight, value] : items) { for (int j = s; j >= weight; --j) { dp[j] = max(dp[j], dp[j - weight] + value); } } cout << dp[s] << "\n"; } int main() { cin.tie(nullptr)->sync_with_stdio(false); solve(); 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...