Submission #1308266

#TimeUsernameProblemLanguageResultExecution timeMemory
1308266ishat_jhaKnapsack (NOI18_knapsack)C++17
0 / 100
146 ms327680 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); int nn, w; cin >> w >> nn; vector<pair<int, pair<int, int>>> vv(nn + 1); int n = 0; for(int i = 1; i <= nn; i++) { cin >> vv[i].first >> vv[i].second.first >> vv[i].second.second; n += vv[i].second.second; } vector<pair<int, int>> v; for(int i = 1; i <= nn; i++) { for(int j = 1; j <= vv[i].second.second; j++) { v.push_back(make_pair(vv[i].second.first, vv[i].first)); } } vector<vector<int>> dp(n + 1, vector<int> (w + 1, 0LL)); for(int i = 0; i < n; i++) { for(int j = 0; j <= w; j++) { dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]); if(j + v[i].first <= w) { dp[i + 1][j + v[i].first] = max(dp[i + 1][j + v[i].first], dp[i][j] + v[i].second); } } } cout << *max_element(dp[n].begin(), dp[n].end()) << 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...