Submission #1020185

#TimeUsernameProblemLanguageResultExecution timeMemory
1020185ArthuroWichKnapsack (NOI18_knapsack)C++17
73 / 100
1089 ms1368 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int void solve() { int s, n; cin >> s >> n; vector<int> dp(s+1, -1); dp[0] = 0; for (int i = 0; i < n; i++) { int v, w, k, l; cin >> v >> w >> k; while(k > 0) { l = log2(k); if (l != 0) { k -= (1<<l)-1; } else { k--; l++; } for (int x = 0; x < l; x++) { for (int j = s; j >= 0; j--) { if (j-(1LL<<x)*w < 0) { break; } if (dp[j-(1LL<<x)*w] != -1) { dp[j] = max(dp[j], dp[j-(1LL<<x)*w]+(1LL<<x)*v); } } } } } int ans = 0; for (int i : dp) { ans = max(ans, i); } cout << ans << endl; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t; t = 1; while(t--) { solve(); } }
#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...