Submission #723877

#TimeUsernameProblemLanguageResultExecution timeMemory
723877ivazivaKnapsack (NOI18_knapsack)C++14
73 / 100
153 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 100010 #define MAXM 2010 long long n; long long s; long long v[MAXN]; long long w[MAXN]; long long k[MAXN]; long long dp[MAXN][MAXM]; int main() { ios_base::sync_with_stdio(false); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>s>>n; for (long long i=1;i<=n;i++) cin>>v[i]>>w[i]>>k[i]; for (long long i=1;i<=n;i++) { for (long long ii=1;ii<=s;ii++) { dp[i][ii]=dp[i-1][ii]; for (long long iii=1;iii<=k[i];iii++) { if (ii>=iii*w[i]) dp[i][ii]=max(dp[i][ii],dp[i-1][ii-iii*w[i]]+iii*v[i]); else break; } } } long long maks=0; for (long long i=1;i<=s;i++) maks=max(maks,dp[n][i]); cout<<maks<<endl; }
#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...