Submission #1082900

#TimeUsernameProblemLanguageResultExecution timeMemory
1082900timmyli3481Knapsack (NOI18_knapsack)C++14
73 / 100
1078 ms24984 KiB
#include <bits/stdc++.h> //#include "stdc++.h" using namespace std; struct grass{ long long v,w,c; }; long long dp[2001]; grass a[100001*30]; int main(){ ios::sync_with_stdio(false); cin.tie(0); 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...