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>
#define int long long
using namespace std;
signed main(){
int s, n; cin >> s >> n;
vector<int> value, weight;
for (int i = 0; i < n; ++i) {
int v, w, k;
cin >> v >> w >> k;
int count = 1;
while (k > 0) {
int currentCount = min(count, k);
value.push_back(currentCount * v);
weight.push_back(currentCount * w);
k -= currentCount;
count <<= 1;
}
}
int totalItems = value.size();
vector<int> dp(s + 1, 0);
for (int i = 0; i < totalItems; ++i) {
for (int j = s; j >= weight[i]; --j) {
dp[j] = max(dp[j], dp[j - weight[i]] + value[i]);
}
}
cout << dp[s] << '\n';
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... |