Submission #1005469

#TimeUsernameProblemLanguageResultExecution timeMemory
1005469kvintsekstakordKnapsack (NOI18_knapsack)C++17
37 / 100
4 ms16220 KiB
#include <bits/stdc++.h> #define int int64_t using namespace std; int S, N; int w[1010]; int v[1010]; int dp[2010][1010]; int32_t main() { cin >> S >> N; int pos = 1; for(int i = 1; i <= N; i++){ int vi, wi, ki; cin >> vi >> wi >> ki; int j; for(j = pos; j < pos+ki; j++){ w[j]=wi; v[j]=vi; } pos = j; } for(int i = 0; i <= pos; i++) dp[0][i]=0; for(int i = 0; i <= S; i++) dp[i][0]=0; for(int i = 1; i <= S; i++){ for(int j = 1; j < pos; j++){ if(i-w[j]<0) dp[i][j]=dp[i][j-1]; else{ dp[i][j]=max(dp[i][j-1], dp[i-w[j]][j-1]+v[j]); } } } cout << dp[S][pos-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...