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 dp[2][2005];
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];
for(int l = 0; l <= s; l++) {
for(int j = 1; j <= k[0]; j++) {
if(w[0] * j > l) break;
dp[0][l] = v[0] * j;
}
}
int a = 0, b = 1;
for(int l = 1; l < n; l++) {
swap(a, b); int i = 0;
for(int j = 0; j <= min(k[l], s); j++) {
for(i = s; w[l] * j <= i; i--)
dp[a][i] = max(dp[a][i], dp[b][i - w[l] * j] + v[l] * j);
}
}
ll res = 0;
for(int l = 0; l <= s; l++) res = max(res, dp[a][l]);
cout << res << "\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... |