Submission #780244

#TimeUsernameProblemLanguageResultExecution timeMemory
780244devariaotaKnapsack (NOI18_knapsack)C++17
0 / 100
87 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int #define cy cout<<"YES"<<endl #define cn cout<<"NO"<<endl #define repp(i,n,k) for(int i=1;i<=n;i+=k) #define repo(i,n,k) for(int i=0;i<n;i+=k) #define pb push_back using namespace std; ll t,n; ll l[100005],e[100005],k[100005]; pair<int,pair<int,int>> arr[100005]; pair<double,int> srt[100005]; ll memo[100005][2005]; ll dp(ll idx,ll duit){ if(idx>n) return 0; if(duit<=0) return 0; if(memo[idx][duit]!=-1) return memo[idx][duit]; ll best=dp(idx+1,duit); for(int i=1;i<=k[idx];i++){ if(duit>=i*e[idx]){ best=max(best,dp(idx+1,duit-i*e[idx])+i*l[idx]); } } return memo[idx][duit]=best; } int main(){ cin>>t>>n; memset(memo,-1,sizeof memo); repp(i,n,1){ cin>>arr[i].first>>arr[i].second.first>>arr[i].second.second; srt[i].first=arr[i].first/arr[i].second.first; srt[i].second=i; } sort(srt+1,srt+n+1,greater<pair<double,int>>()); repp(i,n,1){ l[i]=arr[srt[i].second].first; e[i]=arr[srt[i].second].second.first; k[i]=arr[srt[i].second].second.second; } cout<<dp(1,t); }
#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...