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>
#include <vector>
#include <algorithm>
using namespace std;
struct Item {
int value;
int weight;
int count;
};
int main() {
int N, S;
cin >> N >> S;
vector<Item> items(N);
for (int i = 0; i < N; ++i) {
cin >> items[i].value >> items[i].weight >> items[i].count;
}
vector<long long> dp(S + 1, 0);
for (int i = 0; i < N; ++i) {
int v = items[i].value;
int w = items[i].weight;
int k = items[i].count;
for (int j = 1; k > 0; j <<= 1) {
int count = min(j, k);
k -= count;
long long weight = 1LL * w * count;
long long value = 1LL * v * count;
for (int x = S; x >= weight; --x) {
dp[x] = max(dp[x], dp[x - weight] + value);
}
}
}
cout << dp[S] << endl;
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... |