Submission #947134

#TimeUsernameProblemLanguageResultExecution timeMemory
947134sandrofeiqrishviliKnapsack (NOI18_knapsack)C++14
100 / 100
97 ms3156 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ff first #define ss second #define int long long const int N = 2005, inf=1e18; vector <pair <int, int> > vec[N], g; int dp[N]; int ans=0; signed main(){ int s, n, v, w, r; cin >> s >> n; for(int i=1; i<=n; i++){ cin >> v >> w >> r; vec[w].pb({v,r}); } for (int i=1; i<=s; i++) { sort(vec[i].begin(),vec[i].end()); reverse(vec[i].begin(), vec[i].end()); int tot = s/i; for(int j=0; j<vec[i].size(); j++){ int val = vec[i][j].ff; int raod = vec[i][j].ss; for (int x=1; x<=min(raod, tot); x++) { g.pb({i,val}); } if(tot>=raod){ tot-=raod; } else { tot=0; break; } } } n=g.size(); for(int i=1; i<=n; i++){ int w=g[i-1].ff; int val=g[i-1].ss; for(int j=s; j>=0; j--){ if (j>=w) dp[j]=max(dp[j], dp[j-w]+val); ans=max(ans, dp[j]); } } cout << ans; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:22:17: 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]
   22 |   for(int j=0; j<vec[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...