Submission #973770

#TimeUsernameProblemLanguageResultExecution timeMemory
973770pfkKnapsack (NOI18_knapsack)C++14
73 / 100
1050 ms2900 KiB
#include <iostream> #include <vector> using namespace std; #define mod 1000000007 struct item { int v, w, k; }; long long dp[4005],Max; int s, n; item a[100005]; int main() { cin >> s >> n; for (int i = 1; i <= n; i++) { cin >> a[i].v >> a[i].w >> a[i].k; a[i].k = min(a[i].k, s / a[i].w); } for (int i = 1; i <= n; i++) while (a[i].k--) for (int j = s; j >= a[i].w; j--) dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v); for (int i = 1; i <= s; i++) Max = max(Max, dp[i]); cout << Max; 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...