This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |