Submission #904135

#TimeUsernameProblemLanguageResultExecution timeMemory
904135SalihSahinKnapsack (NOI18_knapsack)C++14
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define mp make_pair using namespace std; const int mod = 1e9 + 7; const int inf = 1e17*2; const int N = 2e5 + 5; int32_t main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int s, n; cin>>s>>n; vector<int> items[s+1]; for(int i = 0; i < n; i++){ int v, w, k; cin>>v>>w>>k; k = min(k, 2047LL); for(int j = 0; j <= 10; j++){ if(w * (1 << j) > s) continue; if(k >= (1 << j)){ k -= (1 << j); items[w * (1 << j)].pb(v * (1 << j)); } } for(int j = 0; j <= 10; j++){ if(w * (1 << j) > s) continue; if(k >= (1 << j)){ k -= (1 << j); items[w * (1 << j)].pb(v * (1 << j)); } } } vector<pair<int, int> > arr; for(int i = 1; i <= s; i++){ sort(items[i].begin(), items[i].end()); while(items[i].size() * i > s){ items[i].pop_back(); } for(auto it: items[i]) arr.pb(mp(i, it)); } vector<int> dp(s+1); for(int i = 0; i < arr.size(); i++){ for(int j = s - arr[i].first; j >= 0; j--){ dp[j + arr[i].first] = max(dp[j + arr[i].first], dp[j] + arr[i].second); } } int ans = 0; for(int i = 0; i <= s; i++){ ans = max(ans, dp[i]); } cout<<ans<<endl; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:40:35: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   40 |         while(items[i].size() * i > s){
      |               ~~~~~~~~~~~~~~~~~~~~^~~
knapsack.cpp:47:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 0; i < arr.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...