제출 #633571

#제출 시각아이디문제언어결과실행 시간메모리
633571IwanttobreakfreeKnapsack (NOI18_knapsack)C++17
100 / 100
111 ms4664 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define int long long #define pii pair<int,int> signed main(){ long long n,s,x,v,k; cin>>s>>n; vector<int> dp(s+1); vector<vector<pii>> elements(s+1,vector<pii>()); for(int i=0;i<n;i++){ cin>>v>>x>>k; elements[x].push_back({v,k}); } for(int i=1;i<=s;i++)sort(elements[i].begin(),elements[i].end()); for(int i=1;i<=s;i++){ int cnt=i; while(cnt<=s&&elements[i].size()){ elements[i].back().second--; for(int j=s;j>=i;j--){ dp[j]=max(dp[j],dp[j-i]+elements[i].back().first); } cnt+=i; //cout<<cnt<<' '; if(!elements[i].back().second)elements[i].pop_back(); } } long long ans=0; for(int i=0;i<=s;i++){ ans=max(ans,dp[i]); } cout<<ans; }
#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...