Submission #761512

#TimeUsernameProblemLanguageResultExecution timeMemory
761512aravboiKnapsack (NOI18_knapsack)C++17
73 / 100
1088 ms2736 KiB
#include <bits/stdc++.h> using namespace std; int main() { int S, N; cin >> S >> N; vector<int> V(N), W(N), K(N); for(int i = 0; i < N; i++) { cin >> V[i] >> W[i] >> K[i]; } vector<vector<int>> dp(2, vector<int>(S + 1)); for(int i /*item*/ = 0; i < N; i++) { for(int w = 0; w <= S; w++) { dp[1][w] = dp[0][w]; for(int k = 1; w - (k * W[i]) >= 0 && k <= K[i]; k++) { dp[1][w] = max(dp[1][w], dp[0][w - (k * W[i])] + k * V[i]); } } for(int w = 0; w <= S; w++) { dp[0][w] = dp[1][w]; dp[1][w] = 0; } } int mx = -1; for(int i = 0; i <= S; i++) { mx = max(mx, dp[0][i]); } cout << mx << "\n"; }
#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...