Submission #1082901

#TimeUsernameProblemLanguageResultExecution timeMemory
1082901timmyli3481Knapsack (NOI18_knapsack)C++14
73 / 100
1094 ms24968 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; scanf("%d%d",&T,&m); int cnt=0; for(int i=1;i<=m;i++){ long long v,w,c; // cin>>v>>w>>c; scanf("%lld%lld%lld",&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]; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d%d",&T,&m);
      |     ~~~~~^~~~~~~~~~~~~~
knapsack.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%lld%lld%lld",&v,&w,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...