Submission #1030485

#TimeUsernameProblemLanguageResultExecution timeMemory
1030485LmaoLmaoKnapsack (NOI18_knapsack)C++14
29 / 100
1 ms364 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using aa = array<int,3>; const int N = 1e6+5; const int INF = 1e9; struct goods { double avg; ll v; int w; ll k; }; bool cmp(goods a,goods b) { return (a.avg<b.avg); } ll dp[2005]; goods a[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,s; cin >> s >> n; for(int i=1;i<=s;i++) { dp[i]=0; } dp[0]=0; for(int i=1;i<=n;i++) { cin >> a[i].v >> a[i].w >> a[i].k; a[i].avg=((a[i].v*1.0)/(a[i].w*1.0)); } sort(a+1,a+1+n,cmp); ll ans=0; for(int i=1;i<=n;i++) { for(ll j=s;j>0;j--) { int m=min(j/a[i].w,a[i].k); if(j>=a[i].w) dp[j]=max(dp[j],dp[j-(m*a[i].w)]+m*a[i].v); ans=max(ans,dp[j]); //cout << dp[j] << ' '; } //cout << endl; } cout << ans; 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...