제출 #976166

#제출 시각아이디문제언어결과실행 시간메모리
976166vjudge1Knapsack (NOI18_knapsack)C++11
12 / 100
1000 ms7156 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define pb push_back struct informasi { ll v, w, stock; }; int main() { ll s, n; cin >> s >> n; vector<informasi> v(n); for (ll i = 0; i < n; i++) { cin >> v[i].v >> v[i].w >> v[i].stock; } vector<pair<ll, ll>> dp[n + 1]; dp[0].pb({s, 0}); set<ll> has[n + 1]; for (ll i = 1; i <= n; i++) { for (auto j : dp[i - 1]) { ll cnt = 0; for (ll w = j.first; w >= max(0LL, j.first - v[i - 1].stock * v[i - 1].w); w -= v[i - 1].w) { if (!has[i].count(w)) { dp[i].pb({w, j.second + cnt * v[i - 1].v}); has[i].insert(w); } else { ll l = 0, r = dp[i].size() - 1; while (l < r) { ll mid = (l + r) / 2; if (dp[i][mid].first == w) { ll incremeter = j.second + cnt * v[i - 1].v; dp[i][mid].second = max(dp[i][mid].second, incremeter); break; } else if (dp[i][mid].first < w) l = mid; else r = mid; } } sort(dp[i].begin(), dp[i].end()); cnt++; } } } ll ans = 0; for (auto i : dp[n]) { ans = max(ans, i.second); } cout << ans; }
#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...