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;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int s; cin >> s;
int n; cin >> n;
vector<tuple<int, int, ll>> stor(n);
for (int i = 0; i < n; i++) {
int a, b;
ll c;
cin >> a >> b >> c;
stor[i] = make_tuple(b, a, min((ll)s / b, c));
}
sort(stor.begin(), stor.end());
vector<ll> dp(s + 1, 0);
ll ans = 0;
for (int i = 0; i < n; i++) {
int weight = get<0>(stor[i]);
int value = get<1>(stor[i]);
ll maxItems = get<2>(stor[i]);
for (int j = 0; j < maxItems; j++) {
for (int x = s; x >= weight; x--) {
dp[x] = max(dp[x], dp[x - weight] + value);
ans = max(ans, dp[x]);
}
}
}
cout << ans << "\n";
}
# | 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... |