Submission #904076

#TimeUsernameProblemLanguageResultExecution timeMemory
904076lambd47Knapsack (NOI18_knapsack)C++14
100 / 100
98 ms2988 KiB
#include<bits/stdc++.h> using namespace std; #define int long long vector<int> dp(2001,-1);//maximo preco que conseguimos fazendo W com itens de peso ate x [x][w] vector<pair<int,int>> pesos[2001]; int32_t main(){ int s,n; cin>>s>>n; for(int i=0;i<n;i++){ int v,w,k; cin>>v>>w>>k; pesos[w].push_back({v,k}); } for(int i=1;i<=s;i++){ sort(pesos[i].begin(),pesos[i].end(),greater<pair<int,int>>()); } dp[0]=0; for(int x=1;x<=s;x++){ int somao=0; for(auto a: pesos[x]){ int val, qnts; int it=0; int qntstot=0; val=a.first, qnts=a.second; while(somao<=s && it<qnts){ somao+=x; it++; qntstot++; for(int i=s;i>=1;i--){ if(i-x>=0){ if(dp[i-x]!=-1)dp[i]=max(dp[i],dp[i-x]+val); //if(x==1)cout<<dp[i-x]; } } } } } int resp=0; for(int i=1;i<=s;i++)resp=max(resp,dp[i]); cout<<resp; }
#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...