제출 #209525

#제출 시각아이디문제언어결과실행 시간메모리
209525model_codeKnapsack (NOI18_knapsack)C++14
100 / 100
93 ms3576 KiB
#include <bits/stdc++.h> #define MAXN 100004 #define MAXS 2004 using namespace std; int s,n,w[MAXN]; long long v[MAXN],k[MAXN],dp[MAXS]; typedef pair<int,int> ii; priority_queue <ii> pq[MAXS]; int main(){ scanf("%d %d",&s,&n); for(int x=0;x<n;x++){ scanf("%lld %d %lld",&v[x],&w[x],&k[x]); pq[w[x]].push(make_pair(v[x],k[x])); } for(int x=1;x<=s;x++){ long long cnt=s/x; while(!pq[x].empty()&&cnt){ ii i=pq[x].top(); pq[x].pop(); if(i.second>cnt) i.second=cnt; cnt-=i.second; for(int y=0;y<i.second;y++) for(int z=s;z>=x;z--) dp[z]=max(dp[z],dp[z-x]+i.first); } } long long ans=0; for(int x=1;x<=s;x++) ans=max(ans,dp[x]); printf("%lld\n",ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

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