제출 #433296

#제출 시각아이디문제언어결과실행 시간메모리
433296AutronKnapsack (NOI18_knapsack)C++14
100 / 100
127 ms4824 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ int s, n; cin>>s>>n; vector<vector<pair<int, int>>> val(s+1, vector<pair<int, int>>(0)); vector<int> dp(s+1, -1e18); for(int i=1;i<=n;++i){ int a, b, c; cin>>a>>b>>c; val[b].push_back({a, c}); } for(int i=1;i<=s;++i) sort(val[i].rbegin(), val[i].rend()); dp[0]=0; for(int i=1;i<=s;++i){ int x=0; for(auto it:val[i]){ for(int j=1;j<=it.second;++j){ x+=i; for(int k=s;k>=x;--k) dp[k]=max(dp[k], dp[k-i]+it.first); if(x>s) break; } if(x>s) break; } } int sol=0; for(int i=0;i<=s;++i) sol=max(sol, dp[i]); cout<<sol<<"\n"; }
#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...