Submission #946729

#TimeUsernameProblemLanguageResultExecution timeMemory
946729hellowinchang1029Knapsack (NOI18_knapsack)C++17
100 / 100
55 ms5580 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define pll pair<ll, ll> #define vvi vector<vector<int>> #define vt vector #define arr array #define ALL(x) begin(x), end(x) #define rALL(x) rbegin(x), rend(x) const int MOD1=998244353; const int MOD2=1e9+7; const ll LINF=1e18; const int INF=1e9; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll s, n; cin>>s>>n; map<ll, vt<pll>> items; for (ll i=0; i<n; i++){ ll v, w, k; cin>>v>>w>>k; items[w].pb({v, k}); } vt<ll> dp(s+1, 0); vt<pll> use_items; for (ll i=1; i<=s; i++){ if (!items[i].size()) continue; sort(rALL(items[i])); for (ll j=0, id=0; j<=(s/i) && id<items[i].size(); j++){ use_items.pb({i, items[i][id].first}); if (!(--items[i][id].second)) id++; } } for (pll item : use_items){ for (ll j=s; j>=item.first; j--){ dp[j]=max(dp[j], dp[j-item.first]+item.second); } } cout<<dp[s]<<'\n'; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:35:39: 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]
   35 |      for (ll j=0, id=0; j<=(s/i) && id<items[i].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...