Submission #528386

#TimeUsernameProblemLanguageResultExecution timeMemory
528386louiskwokKnapsack (NOI18_knapsack)C++17
29 / 100
3 ms1868 KiB
#include <bits/stdc++.h> using namespace std; long long v[100005],w[100005],k[100005]; long long dp[100005][2005],ans; int main() { long long s,n; cin >> s >> n; for (int i=1;i<=n;i++) cin >> v[i] >> w[i] >> k[i]; for (int i=1;i<=n;i++) { for (int j=0;j<=s;j++) { dp[i][j] = max(dp[i][j],dp[i-1][j]); long long num = min(k[i],(s-j)/w[i]); dp[i][j+num*w[i]] = max(dp[i][j+num*w[i]],dp[i-1][j]+v[i]*num); } } for (int i=0;i<=s;i++) ans = max(ans,dp[n][i]); cout << ans << endl; 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...