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 <iostream>
using namespace std;
struct Kue {
long long value, weight, stock;
};
int main() {
int s, n;
cin >> s >> n;
Kue kue[n];
long long total_stock = 0;
for (int i = 0; i < n; i++) {
cin >> kue[i].value >> kue[i].weight >> kue[i].stock;
total_stock += kue[i].stock;
}
long long dp[s + 1] = {0};
int k = 0;
for (int i = 0; i < n; i++) {
for (int w = s; w >= 0; w--) {
auto [val, weight, stock] = kue[i];
if (weight > w) break;
k = min(w / weight, stock);
for (int j = 1; j <= k; j++) {
dp[w] = max(dp[w], dp[w - j * weight] + j * val);
}
}
}
cout << dp[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... |