Submission #1294965

#TimeUsernameProblemLanguageResultExecution timeMemory
1294965notshekKnapsack (NOI18_knapsack)C++20
17 / 100
2 ms1332 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pii pair <int, int> const int N = 10000 + 10; const int S = 2000 + 10; const ll INF = 1e18; int n, k[N], s; ll v[N], w[N], dp[S]; signed main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> s >> n; for (int i = 0; i < n; i++) { cin >> v[i] >> w[i] >> k[i]; } fill(dp, dp + S, -INF); dp[0] = 0; for (int i = 0; i < n; i++) { int p = 1; while (k[i]) { int take = min(p, k[i]); for (int j = s; ~(j - take * w[i]); j--) { dp[j] = max(dp[j], dp[j - take * w[i]] + take * v[i]); } k[i] -= take; p <<= 1; } } cout << *max_element(dp, 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...