Submission #906424

#TimeUsernameProblemLanguageResultExecution timeMemory
906424SalihSahinKnapsack (NOI18_knapsack)C++17
73 / 100
200 ms262144 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; for(int j = 1; j <= min(k, s/w); j++){ items[w].pb(v); } /* vector<int> cnt(11); cnt[0] = min(k, 2048LL); for(int i = 0; i < 10; i++){ int x = (cnt[i] - 1)/2; cnt[i] -= x*2; cnt[i+1] += x; } for(int i = 0; i < 10; i++){ if((1 << i) * w > s) break; for(int j = 0; j < cnt[i]; j++){ items[w * (1 << i)].pb(v * (1 << i)); } } */ } vector<pair<int, int> > arr; for(int i = 1; i <= s; i++){ sort(items[i].rbegin(), items[i].rend()); 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:45:35: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   45 |         while(items[i].size() * i > s){
      |               ~~~~~~~~~~~~~~~~~~~~^~~
knapsack.cpp:52: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]
   52 |     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...