Submission #876433

#TimeUsernameProblemLanguageResultExecution timeMemory
876433arkash707Knapsack (NOI18_knapsack)C++17
49 / 100
1094 ms440 KiB
#include<iostream> #include<vector> using namespace std; long long s, n; //good: {price, weight, quantity} long long a[100001][3]; long long solve() { long long dp[s+1]; for (int i=0; i<=s; i++) dp[i] = -1; dp[0] = 0; long long res = 0; for (int i=0; i<n; i++) { long long p = a[i][0], w = a[i][1], q = a[i][2]; for (int j=s; j>=0; j--) { if (dp[j] == -1) continue; for (int k=0; k<=q; k++) { if (j+w*k > s) continue; dp[j+w*k] = max(dp[j+w*k], dp[j] + p*k); res = max(res, dp[j+w*k]); } } } return res; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif cin >> s >> n; for (int i=0; i<n; i++) { for (int j=0; j<3; j++) { cin >> a[i][j]; } } cout << solve() << "\n"; }
#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...