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;
int main() {
int N, S;
cin >> N >> S;
vector<int> V(N), W(N), K(N);
for (int i = 0; i < N; ++i) {
cin >> V[i] >> W[i] >> K[i];
}
vector<long long> dp(S + 1, 0);
for (int i = 0; i < N; ++i) {
int value = V[i];
int weight = W[i];
int count = K[i];
for (int k = 1; k <= count; k <<= 1) {
for (int w = S; w >= weight * k; --w) {
dp[w] = max(dp[w], dp[w - weight * k] + value * k);
}
count -= k;
}
if (count > 0) {
for (int w = S; w >= weight * count; --w) {
dp[w] = max(dp[w], dp[w - weight * count] + value * count);
}
}
}
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... |