Submission #1103510

#TimeUsernameProblemLanguageResultExecution timeMemory
1103510Mauricio_CruzKnapsack (NOI18_knapsack)C++14
100 / 100
73 ms36168 KiB
#include <bits/stdc++.h> using namespace std; #define srtl(x)sort((x).begin(),(x).end()) #define srtg(x)sort((x).begin(),(x).end(),greater<>()) #define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define f first #define s second #define pb push_back #define pii pair<int,int> #define ins insert #define vi vector<int> #define vii vector<pii> #define viii vector<pair<int,pii>> int ax[4]={0,1,0,-1}; int ay[4]={1,0,-1,0}; #define int long long int32_t main(){ ios; int k,n; cin>>k>>n; vii a[k+1]; int t=0; for(int i=0;i<n;i++){ int x,y,z; cin>>x>>y>>z; if(a[y].empty())t++; a[y].pb({x,z}); } int u=0; vector<vi>dp(t+2,vi(k+1,0)); for(int i=1;i<=k;i++){ if(a[i].empty())continue; u++; srtg(a[i]); int az=a[i].size(); for(int j=0;j<=k;j++){ dp[u][j]=max(dp[u][j],dp[u-1][j]); if(j<i)continue; int us=0; int ind=0; int sum=0; for(int cn=i;cn<=j&&us<az;cn+=i){ sum+=a[i][us].f; dp[u][j]=max(dp[u][j],dp[u-1][j-cn]+sum); ind++; if(ind==a[i][us].s){ ind=0; us++; } } } } int res=0; for(int i:dp[t])res=max(res,i); cout<<res; 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...