Submission #465056

#TimeUsernameProblemLanguageResultExecution timeMemory
465056Qw3rTyKnapsack (NOI18_knapsack)C++11
100 / 100
141 ms9944 KiB
#include <bits/stdc++.h> #define int long long #define pi pair<int,int> #define fi first #define se second #define pb push_back using namespace std; const int maxN = 1e5+5; const int maxV = 2e3+5; vector<int> d[maxV]; int S,N; int f[maxV]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); //freopen("../test.in","r",stdin); cin >> S >> N; for(int i = 1; i <= N; ++i){ int v,w,k; cin >> v >> w >> k; for(int j = 1; j <= k; j <<= 1){ if(w * j > S)break; k -= j; d[w*j].pb(v*j); } if(k > 0 && w * k <= S)d[w*k].pb(v*k); } for(int i = 1; i <= S; ++i){ if(d[i].size()){ //for each group of objects w/ weight = i sort(d[i].begin(),d[i].end(),greater<int>()); //Consider only the first floor(S/W) objects int num = min(S/i,(int)(d[i].size())); assert(d[i].size() >= num); for(int j = 0; j < num; ++j){ for(int k = S; k >= i; --k){ f[k] = max(f[k],f[k-i] + d[i][j]); } } } } cout << f[S] << '\n'; }

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from knapsack.cpp:1:
knapsack.cpp: In function 'int main()':
knapsack.cpp:35:23: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   35 |    assert(d[i].size() >= num);
      |           ~~~~~~~~~~~~^~~~~~
#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...