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;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int W, n;
cin >> W >> n;
vector<array<long long, 2>> a;
for (int i = 0; i < n; i++) {
long long v, w, cnt;
cin >> v >> w >> cnt;
long long coef = 1;
while (coef <= cnt) {
a.push_back({ coef * v, coef * w });
coef *= 2;
}
}
n = a.size();
vector<vector<long long>> dp(n + 1, vector<long long>(W + 1, 0));
for (int i = 1; i <= n; i++) {
for (int w = 0; w <= W; w++) {
if (w - a[i - 1][1] >= 0) {
dp[i][w] = max( dp[i][w], dp[i - 1][w - a[i - 1][1]] + a[i - 1][0] );
}
}
}
cout << *max_element(dp[n].begin(), dp[n].end()) << "\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... |