Submission #1111996

#TimeUsernameProblemLanguageResultExecution timeMemory
1111996vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
1091 ms84324 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int S=2005; const int N=1e5+5; int s,n,value[N],weight[N],stock[N],dp[S][N]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> s >> n; for(int i=1;i<=n;i++) cin >> value[i] >> weight[i] >> stock[i]; for(int i=1;i<=s;i++){ for(int j=1;j<=n;j++){ dp[i][j]=dp[i-1][j]; for(int k=0;k<=stock[j] && k*weight[j]<=i;k++){ if(k*weight[j]<=i) dp[i][j]=max(dp[i][j],dp[i-k*weight[j]][j-1]+value[j]*k); } } } cout << dp[s][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...