Submission #766621

#TimeUsernameProblemLanguageResultExecution timeMemory
766621fdnfksdKnapsack (NOI18_knapsack)C++14
100 / 100
54 ms7456 KiB
#include<bits/stdc++.h> #define int long long using namespace std; using ll = long long; const ll maxN=2e5; ll s,n,v[maxN],w[maxN],k[maxN]; priority_queue<pair<int,int>>pq[2006]; #define fi first #define se second #define pb push_back ll dp[2006]; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> s >> n; for(int i=1;i<=n;i++) { cin >> v[i] >> w[i] >> k[i]; pq[w[i]].push({v[i],k[i]}); } vector<pair<int,int>> vec; for(int i=1;i<=s;i++) { ll need=s/i; while(pq[i].size()>0) { ll x=min(pq[i].top().se,need); need-=x; for(int j=1;j<=x;j++) vec.pb({i,pq[i].top().fi}); auto tp=pq[i].top(); pq[i].pop(); tp.se-=x; if(tp.se>0) pq[i].push(tp); if(need==0) break; } } for(int i=0;i<vec.size();i++) { for(int j=s;j>=vec[i].fi;j--) dp[j]=max(dp[j],dp[j-vec[i].fi]+vec[i].se); } ll ans=0; for(int j=0;j<=s;j++) ans=max(ans,dp[j]); cout << ans; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:38:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<vec.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...