Submission #1046609

#TimeUsernameProblemLanguageResultExecution timeMemory
1046609NewtonabcKnapsack (NOI18_knapsack)C++14
73 / 100
1036 ms17100 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,sum=0; cin>>a >>b >>c; long long 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++){ 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:12:19: warning: unused variable 'sum' [-Wunused-variable]
   12 |   long long a,b,c,sum=0;
      |                   ^~~
knapsack.cpp:23: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]
   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...