Submission #676415

#TimeUsernameProblemLanguageResultExecution timeMemory
676415ProCallerAJKnapsack (NOI18_knapsack)C++17
17 / 100
1 ms1108 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, e) for (int i = 0; i < (e); i++) #define FOR1(i, e) for (int i = 1; i <= (e); i++) #define ull unsigned long long int #define pii pair <int, int> #define value first.first #define weight first.second #define quantity second int n, s; pair<pii, int> items[100000]; int dp[100001][2001]; int main(){ cin >> s >> n; FOR(i, n){ cin >> items[i].value >> items[i].weight >> items[i].quantity; } FOR1(i, n) { for (int j = 0; j <= s; j++) { dp[i][j] = dp[i - 1][j]; if (j >= items[i - 1].weight){ dp[i][j] = max(dp[i][j], dp[i - 1][j - items[i - 1].weight] + items[i - 1].value); } } } cout << dp[n][s]; 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...