Submission #1046588

#TimeUsernameProblemLanguageResultExecution timeMemory
1046588NewtonabcKnapsack (NOI18_knapsack)C++14
73 / 100
1048 ms18120 KiB
#include<bits/stdc++.h> using namespace std; const int N=2e3+10; vector<pair<long long,long long> > v; int dp[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int s,n; cin>>s >>n; while(n--){ long long a,b,c; cin>>a >>b >>c; long long tmp=1; while(c>=tmp){ if(b*tmp<=s) 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++){ long long 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-(int)wg]+(int)val); } } cout<<dp[s]; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:22:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  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...