Submission #1020159

#TimeUsernameProblemLanguageResultExecution timeMemory
1020159ArthuroWichKnapsack (NOI18_knapsack)C++17
37 / 100
1056 ms384 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; cin >> v >> w >> k; for (int x = 1; x <= k; x++) { for (int j = s; j >= 0; j--) { if (j-w < 0) { break; } if (dp[j-w] != -1) { dp[j] = max(dp[j], dp[j-w]+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...