제출 #1046610

#제출 시각아이디문제언어결과실행 시간메모리
1046610NewtonabcKnapsack (NOI18_knapsack)C++14
37 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; const int N=2e3+10; vector<pair<int,int> > v; int dp[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int s,n; cin>>s >>n; while(n--){ int a,b,c,sum=0; cin>>a >>b >>c; int tmp=1; while(c>=tmp){ if(b*tmp>s) break; v.push_back(make_pair(a*tmp,b*tmp)); c-=tmp; tmp*=2; } if(b*c<=s) v.push_back(make_pair(a*c,b*c)); } for(int i=0;i<v.size();i++){ int val=v[i].first,wg=v[i].second; for(int j=s;j>=1;j--){ if(j-wg<0) break; dp[j]=max(dp[j],dp[j-wg]+val); } } cout<<dp[s]; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:12:13: warning: unused variable 'sum' [-Wunused-variable]
   12 |   int a,b,c,sum=0;
      |             ^~~
knapsack.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i=0;i<v.size();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...