제출 #1092106

#제출 시각아이디문제언어결과실행 시간메모리
1092106vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
38 ms5212 KiB
#include <bits/stdc++.h> #define int long long #define pb push_back using namespace std; const int maxn = 1e5 + 10, maxs = 2e3 + 10; int s, n, dp[maxs]; vector <pair <int, int>> item[maxn]; int32_t main (){ ios_base::sync_with_stdio(0); cin >> s >> n; for (int v, w, k, i = 0; i < n; i++) cin >> v >> w >> k, item[w].pb({v, k}); for (int i = 1; i <= s; i++){ sort(item[i].begin(), item[i].end(), greater<pair <int, int>>()); int w = 0; for (auto [v, k] : item[i]){ while (w + i <= s && k){ k--; w += i; for (int j = s; j >= i; j--) dp[j] = max(dp[j], dp[j - i] + v); } if (w + i > s) break; } } 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...