제출 #932469

#제출 시각아이디문제언어결과실행 시간메모리
932469ironicKnapsack (NOI18_knapsack)C++17
100 / 100
62 ms4408 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve(){ int s, n; cin >> s >> n; map<int, vector<pair<int, int>>> mp; int arr[3]; for(int i = 0; i<n; i++){ cin >> arr[0] >> arr[1] >> arr[2]; mp[arr[1]].push_back({arr[0], arr[2]}); } int a[s+1]{}; memset(a, -1e9, sizeof(a)); a[0] = 0; for(auto j : mp){ int w = j.first; sort(j.second.rbegin(), j.second.rend()); int amt = s/w; for(auto item : j.second){ if(!amt) break; for(int i = 0; i<item.second; i++){ if(!amt) break; amt--; for(int u = s; u>=w; u--) a[u] = max(a[u], a[u-w]+item.first); } } } // for(int i = 0; i<=s; i++) cout << a[i] << ' '; cout << *max_element(a, a+s+1) << '\n'; } signed main() { // #ifndef LOCAL // freopen(".in","r",stdin); // freopen(".out","w",stdout); // #endif ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while(t--) solve(); }
#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...