Submission #1005627

#TimeUsernameProblemLanguageResultExecution timeMemory
1005627kvintsekstakordKnapsack (NOI18_knapsack)C++17
37 / 100
4 ms16216 KiB
#include <bits/stdc++.h> #define int int64_t using namespace std; int S, N; vector<vector<pair<int, int> > > vk(2010, vector<pair<int, int>>()); vector<int> w={0}; vector<int> v={0}; int dp[2010][1010]; int32_t main() { cin >> S >> N; if(N==1){ int vi, wi, ki; cin >> vi >> wi >> ki; } for(int i = 1; i <= N; i++){ int vi, wi, ki; cin >> vi >> wi >> ki; vk[wi].push_back({vi, ki}); } for(int i = 1; i <= 2000; i++){ sort(vk[i].begin(), vk[i].end(), greater<pair<int, int> >()); int sum = 0; for(int j = 0; j < vk[i].size(); j++){ int vi = vk[i][j].first; int k = vk[i][j].second; int e; if(sum+k<=(2000/i)){ e=k; sum+=k; }else{ e = (2000/i)-sum; sum = (2000)/i; } for(int z = 0; z < k; z++){ w.push_back(i); v.push_back(vi); } if(sum==(2000)/i) break; } } for(int i = 0; i <= w.size(); i++) dp[0][i]=0; for(int i = 0; i <= S; i++) dp[i][0]=0; for(int i = 1; i <= S; i++){ for(int j = 1; j < w.size(); j++){ if(i-w[j]<0) dp[i][j]=dp[i][j-1]; else{ dp[i][j]=max(dp[i][j-1], dp[i-w[j]][j-1]+v[j]); } } } cout << dp[S][w.size()-1]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:29:26: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int j = 0; j < vk[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~
knapsack.cpp:33:17: warning: variable 'e' set but not used [-Wunused-but-set-variable]
   33 |             int e;
      |                 ^
knapsack.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i = 0; i <= w.size(); i++) dp[0][i]=0;
      |                    ~~^~~~~~~~~~~
knapsack.cpp:57:26: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for(int j = 1; j < w.size(); j++){
      |                        ~~^~~~~~~~~~
#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...