Submission #463623

#TimeUsernameProblemLanguageResultExecution timeMemory
463623lto5Knapsack (NOI18_knapsack)C++17
100 / 100
132 ms1632 KiB
#include<bits/stdc++.h> using namespace std; vector<pair<int, int>> items[2005]; long long dp[2005]; int main(){ long long s; int n; cin >> s >> n; for(int i = 1; i <= n; i++){ int v, w, k; cin >> v >> w >> k; items[w].push_back({v, k}); } for(int i = 1; i <= s; i++){ sort(items[i].rbegin(), items[i].rend()); long long curr = 0;//, curr_v = 0; for(const auto &[v, k] : items[i]){ if(curr > s) break; for(int j = 1; j <= k && curr <= s; j++){ curr += i; // curr_v += v; for(int w = s; w >= curr; w--) dp[w] = max(dp[w], dp[w - i] + v); } } } cout << dp[s]; }
#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...