Submission #1082899

#TimeUsernameProblemLanguageResultExecution timeMemory
1082899timmyli3481Knapsack (NOI18_knapsack)C++14
73 / 100
1073 ms23748 KiB
#include <bits/stdc++.h> //#include "stdc++.h" using namespace std; struct grass{ long long v,w,c; }; long long dp[10000001]; grass a[100001]; int main(){ int T,m; cin>>T>>m; int cnt=0; for(int i=1;i<=m;i++){ long long v,w,c; cin>>v>>w>>c; int t=1; while(t<=c){ a[++cnt].v=v*t; a[cnt].w=w*t; c-=t; t*=2; } if(c>0){ a[++cnt].v=v*c; a[cnt].w=w*c; } } for(int i=1;i<=cnt;i++){ for(int j=T;j>=a[i].w;j--){ dp[j]=max(dp[j],dp[j-a[i].w]+a[i].v); } } cout<<dp[T]; }
#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...