Submission #847733

#TimeUsernameProblemLanguageResultExecution timeMemory
847733dubabubaKnapsack (NOI18_knapsack)C++14
73 / 100
127 ms262144 KiB
#include<bits/stdc++.h> using namespace std; const int mxn = 1e5 + 10; const int mxs = 2000 + 9; int dp[mxn][mxs], n, s, ans; int pr[mxn], we[mxn], am[mxn]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> s >> n; for(int i = 1; i <= n; i++) cin >> pr[i] >> we[i] >> am[i]; for(int i = 1; i <= n; i++) for(int j = 0; j <= s; j++) { for(int k = 0; k <= am[i] && k * we[i] <= j; k++) dp[i][j] = max(dp[i][j], dp[i-1][j - we[i] * k] + pr[i] * k); ans = max(ans, dp[i][j]); } cout << ans << '\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...