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;
const int N = 1e6 + 17;
int s, n, v[N], w[N], k[N], sz;
long long f[N], c;
vector <pair <int, int>> sw[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s >> n;
for (int i = 1; i <= n; ++i)
{
cin >> v[i] >> w[i] >> k[i];
sw[w[i]].push_back({v[i], k[i]});
}
n = 0;
for (int ww = 1; ww <= 1e6; ++ww)
{
sort (sw[ww].begin(), sw[ww].end(), greater<>());
int c = 0;
for (auto [vv, kk]: sw[ww])
{
if (c < s / ww)
{
++n;
v[n] = vv, w[n] = ww, k[n] = min (kk, s / ww - c);
c += min (kk, s / ww - c);
continue;
}
break;
}
}
for (int i = 1; i <= n; ++i)
{
for (int j = s; j >= 1; --j)
{
for (int t = 1; t <= k[i] && t * w[i] <= j; ++t)
{
f[j] = max (f[j], f[j - t * w[i]] + 1LL * t * v[i]);
}
}
}
cout << f[s];
}
# | 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... |