Submission #484431

#TimeUsernameProblemLanguageResultExecution timeMemory
484431maxshevKnapsack (NOI18_knapsack)C++14
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> using namespace std; int main() { ifstream fin("knapsack.in"); int s, n; fin >> s >> n; long v[2001], w[2001], k[2001]; for (int i = 1; i <= n; i++) { fin >> v[i] >> w[i] >> k[i]; } long dp[2001]; dp[0] = 0; for (int i = 1; i <= n; i++) { for (int x = s; x >= 0; x--) { for (int j = 0; j <= k[i]; j++) { if (x >= j * w[i]) { dp[x] = max(dp[x], dp[x - (j * w[i])] + (j * v[i])); } } } } cout << dp[s] << '\n'; 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...