Submission #784693

#TimeUsernameProblemLanguageResultExecution timeMemory
7846930x34cKnapsack (NOI18_knapsack)C++17
73 / 100
143 ms262144 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int s, n; cin >> s >> n; int val[n], wei[n], mult[n]; for (int i = 0; i < n; i++) cin >> val[i] >> wei[i] >> mult[i]; ll dp[n][s + 1]; for (int i = 0; i < n; i++) { for (int j = 0; j <= s; j++) { if (i == 0 && j == 0) dp[i][j] = 0; else if (i == 0) { dp[i][j] = 0; if (wei[i] <= j) { dp[i][j] = (ll)min(j / wei[i], mult[i]) * (ll)val[i]; } } else { dp[i][j] = dp[i - 1][j]; for (int m = 1; m <= mult[i] && j >= wei[i] * m; m++) dp[i][j] = max(dp[i][j], dp[i - 1][j - wei[i] * m] + (ll)val[i] * (ll)m); } } } cout << dp[n - 1][s] << endl; }
#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...