Submission #779130

#TimeUsernameProblemLanguageResultExecution timeMemory
779130c2zi6Knapsack (NOI18_knapsack)C++14
73 / 100
188 ms262144 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n, s; cin >> s >> n; vector<int> v(n+1), w(n+1), k(n+1); for (int i = 1; i <= n; i++) { cin >> v[i] >> w[i] >> k[i]; } ll dp[n+1][s+1]; for (int i = 0; i <= s; i++) dp[0][i] = -1e17; dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= s; j++) { dp[i][j] = -1e17; for (int cnt = 0; cnt <= k[i]; cnt++) { if (j - w[i]*cnt < 0) break; dp[i][j] = max(dp[i][j], dp[i-1][j - w[i]*cnt] + v[i]*cnt); } } } ll ans = 0; for (int i = 0; i <= s; i++) ans = max(ans, dp[n][i]); cout << ans << endl; } int main() { int t = 1; //cin >> t; while (t--) solve(); 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...