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;
typedef long long ll;
struct item {
ll v, w;
};
int S, N;
ll dp[2001];
item arr[33000000];
int main() {
cin >> S >> N;
ll ctr = 0;
for (int i = 0; i < N; i++) {
ll v, w, k; cin >> v >> w >> k;
ll c = 1;
while (c < k) {
k -= c;
arr[++ctr].v = v * c;
arr[ctr].w = w * c;
c *= 2;
}
arr[++ctr].v = v * k;
arr[ctr].w = w * k;
}
for (int i = 1; i <= ctr; i++) {
for (int j = S; j >= arr[i].w; j--) {
dp[j] = max(dp[j], dp[j - arr[i].w] + arr[i].v);
}
}
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... |