Submission #826013

#TimeUsernameProblemLanguageResultExecution timeMemory
826013dijbkrKnapsack (NOI18_knapsack)C++14
49 / 100
16 ms15712 KiB
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; const ll maxn=200005; ll n,m; ll v[2001]; ll w[2001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; ll sum=0; ll pos=1; if (m==1) { int x,y,z; cin >> x >> y >> z; int cur=n/y; cur=min(cur,z); cout << x*cur; return 0; } for (ll i=1; i<=m; i++) { ll k; cin >> v[pos] >> w[pos] >> k; sum+=k; for (ll j=pos+1; j<pos+k; j++) { v[j]=v[pos]; w[j]=w[pos]; } pos=pos+k; } ll dp[sum+4][n+4]; memset(dp,0,sizeof(dp)); for (ll j=1; j<=n; j++) { for (ll i=1; i<=sum; i++) { dp[i][j]=dp[i-1][j]; if (j-w[i]>=0) { dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]); } } } ll ans=0; for (ll i=1; i<=n; i++) { ans=max(ans,dp[sum][i]); } cout << ans; }
#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...