Submission #1172376

#TimeUsernameProblemLanguageResultExecution timeMemory
1172376dbekarysKnapsack (NOI18_knapsack)C++20
37 / 100
1096 ms49728 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int S, N; cin >> S >> N; vector<int> weights, values; for (int i = 0; i < N; i++) { int value, weight, count; cin >> value >> weight >> count; // Binary representation for item multiplicity for (int power = 1; power <= count; power++) { weights.push_back(weight); values.push_back(value); } } vector<int> dp(S + 1, 0); for (int i = 0; i < weights.size(); i++) { for (int j = S; j >= weights[i]; j--) { dp[j] = max(dp[j], dp[j - weights[i]] + values[i]); } } 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...