Submission #826000

#TimeUsernameProblemLanguageResultExecution timeMemory
826000dijbkrKnapsack (NOI18_knapsack)C++14
17 / 100
2 ms3668 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; 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[m+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...