Submission #857159

#TimeUsernameProblemLanguageResultExecution timeMemory
857159neodoomerKnapsack (NOI18_knapsack)C++14
73 / 100
154 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define pi pair<int,int> int s; int knapsack ( vector<pair<ll,ll> >& vw ){ int n=vw.size(); ll dp[n+1][s+1]; for(int i=0;i<=n;i++) for(int w=0;w<=s;w++) dp[i][w]=-1e18; ll ans=0; dp[0][0]=0; for(int i=1;i<=n;i++) { for(int w=0;w<=s;w++) { dp[i][w]=dp[i-1][w]; if(w-vw[i-1].S>=0) dp[i][w]=max(dp[i][w],dp[i-1][w-vw[i-1].S]+vw[i-1].F); ans=max(ans,dp[i][w]); } } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n; cin>>s>>n; vector< vector<pair<ll,ll> > > a(s+1); vector<ll> counter(s+1); for(int i=0;i<n;i++) { ll v,w,k; cin>>v>>w>>k; counter[w]+=k; a[w].pb({v,k}); } vector<pair<ll,ll> > important; for(int i=1;i<=s;i++) { if(a[i].empty())continue; sort(a[i].begin(),a[i].end()); ll need = s/i +1; for(int j=a[i].size()-1;j>=0;j--) { ll x=min(need,a[i][j].S); for(int z=0;z<x;z++) important.pb({a[i][j].F,i}),need--; } } cout<<knapsack(important); return 0; }
#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...