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;
struct item {
int weight, price, count;
};
int main() {
int s, n;
cin >> s >> n;
vector<item> items(n);
for (int i = 0; i < n; ++i) {
cin >> items[i].price >> items[i].weight >> items[i].count;
}
vector<int> dp(s + 1, 0);
for (int i = 0; i < n; ++i) {
for (int x = s; x >= 0; --x) {
for (int count = 1; count <= items[i].count; ++count) {
if (count * items[i].weight > x)
break;
dp[x] = max(dp[x], dp[x - count * items[i].weight] +
items[i].price * count);
}
}
}
cout << dp[s] << "\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... |