Submission #759825

#TimeUsernameProblemLanguageResultExecution timeMemory
759825sofija6Knapsack (NOI18_knapsack)C++14
73 / 100
317 ms262144 KiB
#include <bits/stdc++.h> #define ll long long #define MAXN 100010 #define MAXS 2010 using namespace std; vector<pair<ll,ll> > val[MAXS]; vector<ll> cnt[MAXN]; ll dp[MAXS],v[MAXN],w[MAXN],k[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll s,n,ans=0; cin >> s >> n; for (ll i=1;i<=n;i++) { cin >> v[i] >> w[i] >> k[i]; for (ll j=1;j<=k[i] && j*w[i]<=s;j++) val[j*w[i]].push_back({j*v[i],i}); } for (ll i=1;i<=s;i++) { sort(val[i].begin(),val[i].end(),greater<pair<ll,ll> >()); for (ll j=0;j<val[i].size() && (j+1)*i<=s;j++) cnt[val[i][j].second].push_back(i/w[val[i][j].second]); } for (ll i=1;i<=n;i++) { for (ll j=s;j>=0;j--) { for (ll l : cnt[i]) { if (j+l*w[i]>s) break; dp[j+l*w[i]]=max(dp[j+l*w[i]],dp[j]+l*v[i]); } } } for (ll i=0;i<=s;i++) ans=max(ans,dp[i]); cout << ans; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:23: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]
   23 |         for (ll j=0;j<val[i].size() && (j+1)*i<=s;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...