Submission #876157

#TimeUsernameProblemLanguageResultExecution timeMemory
876157CBG6682Knapsack (NOI18_knapsack)C++14
73 / 100
1020 ms33588 KiB
#include <bits/stdc++.h> using namespace std; const int MAXX = 1e5 + 5; int s,n,dp[2001][MAXX]; struct Product{ int v,w,k; }; Product product[MAXX]; bool cmp(Product a, Product b){ return a.w < b.w; } int main(){ cin >> s >> n; for (int i = 0; i < n; i++) cin >> product[i].v >> product[i].w >> product[i].k; sort(product,product + n,cmp); for (int i = 1; i <= s; i++){ for (int j = 0; j < n; j++){ if (i >= product[j].w){ int num = 1; while (num*product[j].w <= i && num <= product[j].k){ dp[i][j] = max(max(dp[i - num*product[j].w][j - 1] + product[j].v*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...