Submission #698023

#TimeUsernameProblemLanguageResultExecution timeMemory
698023xr_cKnapsack (NOI18_knapsack)C++17
73 / 100
1090 ms2328 KiB
#include <cstring> #include <iostream> using namespace std; int s, n, w[100001], v[100001], k[100001]; int dp[2001]; int main() { // freopen("debug.cerr", "w", stderr); memset(dp, 0, sizeof(dp)); cin >> s >> n; for (int i = 1; i <= n; i++) { cin >> v[i] >> w[i] >> k[i]; } // for (int i = 1; i <= n; i++) // cerr << k[i] << ' '; // cerr << endl; for (int i = 1; i <= n; i++) { for (int j = s; j >= 1; j--) { for (int l = 1; l <= k[i] && l * w[i] <= j; l++) { dp[j] = max(dp[j], dp[j - l * w[i]] + l * v[i]); } } } // for (int i = 1; i <= n; i++) { // for (int j = 1; j <= s; j++) { // cerr << dp[i][j] << '\t'; // } // cerr << endl; // } cout << dp[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...