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;
#define int long long
int S, N, dp[2001], peso[3000000], val[3000000];
int32_t main() {
cin >> S >> N;
int ctr = 0;
for (int i = 0; i < N; i++) {
int c = 1, v, w, k; cin >> v >> w >> k;
while (c < k) {
k -= c;
peso[++ctr] = w * c;
val[ctr] = v * c;
c *= 2;
}
peso[++ctr] = w * k;
val[ctr] = v * k;
}
for (int i = 1; i <= ctr; i++) {
for (int j = S; j >= peso[i]; j--) {
dp[j] = max(dp[j], dp[j - peso[i]] + val[i]);
}
}
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... |