제출 #713622

#제출 시각아이디문제언어결과실행 시간메모리
713622NNerverKnapsack (NOI18_knapsack)C++14
100 / 100
290 ms4864 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; int N,S; int cntw[MAXN]; int v[MAXN],w[MAXN],k[MAXN]; vector<pair<int, pair<int,int> > > vec; int dp[MAXN]; void update(int V,int W){ for(int i=S;i>=W;i--){ dp[i]=max(dp[i],dp[i-W]+V); } } int main(){ scanf("%d%d",&S,&N); for(int i=1;i<=N;i++){ scanf("%d%d%d",&v[i],&w[i],&k[i]); vec.push_back({-v[i],{w[i],k[i]}}); } sort(vec.begin(),vec.end()); for(int i=0;i<N;i++){ int V=-vec[i].first; int W=vec[i].second.first; int kk=vec[i].second.second; int K=min(kk,S/W); if(cntw[W]>=S) continue; cntw[W]+=kk; int cnt=1; for(;cnt<=K;cnt*=2){ update(V*cnt,W*cnt); K-=cnt; } update(V*K,W*K); } printf("%d\n",dp[S]); return 0; }

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

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