Submission #1294976

#TimeUsernameProblemLanguageResultExecution timeMemory
1294976notshekKnapsack (NOI18_knapsack)C++20
73 / 100
1067 ms2796 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pii pair <int, int> const int N = 1e5 + 10; const int S = 2000 + 10; const ll INF = 1e18; ll 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]; k[i] = min(k[i], s); } fill(dp, dp + S, -INF); dp[0] = 0; for (int i = 0; i < n; i++) { ll p = 1; while (k[i]) { ll take = min(p, k[i]); for (ll j = s; j - take * w[i] >= 0; 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...