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;
using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
ll s, n; ll v[2 * 100005], w[2 * 100005], k[2 * 100005];
ll solve(ll i, ll t_left) {
if(i == n || t_left == 0) return 0;
ll best = solve(i + 1, t_left);
for(ll l = 1; l <= k[i]; l++) {
if(w[i] * l > t_left) break;
best = max(best, v[i] * l + solve(i + 1, t_left - w[i] * l));
}
return best;
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> s >> n;
for(ll l = 0; l < n; l++) cin >> v[l] >> w[l] >> k[l];
cout << solve(0, s) << "\n";
return 0;
}
# | 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... |