Submission #330040

#TimeUsernameProblemLanguageResultExecution timeMemory
330040oakKnapsack (NOI18_knapsack)C++14
100 / 100
97 ms5100 KiB
#include<bits/stdc++.h> using namespace std; vector<pair<long long,int> > wei[2001],vc; long long dp[2001]; int main(){ int n,s,i,j,w,k; long long v; scanf("%d %d",&s,&n); for(i=0;i<n;i++){ scanf("%lld %d %d",&v,&w,&k); wei[w].push_back(make_pair(v,k)); } for(i=1;i<=s;i++){ sort(wei[i].begin(),wei[i].end(),greater<pair<long long,int> >()); int remain = s/i; for(j = 0; j<wei[i].size() && remain >0; j++){ int sel = min(remain,wei[i][j].second); remain -= sel; while(sel--)vc.push_back(make_pair(wei[i][j].first,i)); } } for(i=0;i<vc.size();i++){ for(j = s;j >= vc[i].second;j--){ dp[j] = max(dp[j],dp[j-vc[i].second] + vc[i].first); } } printf("%lld",dp[s]); }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:16:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for(j = 0; j<wei[i].size() && remain >0; j++){
      |              ~^~~~~~~~~~~~~~
knapsack.cpp:22:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(i=0;i<vc.size();i++){
      |          ~^~~~~~~~~~
knapsack.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |  scanf("%d %d",&s,&n);
      |  ~~~~~^~~~~~~~~~~~~~~
knapsack.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |   scanf("%lld %d %d",&v,&w,&k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...