Submission #875985

#TimeUsernameProblemLanguageResultExecution timeMemory
875985CBG6682Knapsack (NOI18_knapsack)C++14
12 / 100
11 ms12636 KiB
#include <bits/stdc++.h> using namespace std; const int MAXX = 1e5 + 5; int s,n,v[MAXX],w[MAXX],dp[2001][MAXX],k[MAXX]; int main(){ cin >> s >> n; for (int i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i]; for (int i = 1; i <= s; i++){ for (int j = 0; j < n; j++){ if (i >= w[j]){ int num = 1; while (num*w[j] <= i && num <= k[j]){ dp[i][j] = max(max(dp[i - num*w[j]][j - 1] + v[j]*num,dp[i][j]),max(dp[i - 1][j],dp[i][j - 1])); num++; } } } } cout << dp[s][n - 1]; 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...