이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int limitWeight, numItem;
std::cin >> limitWeight >> numItem;
std::vector<std::pair<int, int>> items;
for (int index = 0; index < numItem; index++) {
int value, weight, amount;
std::cin >> value >> weight >> amount;
int power2 = 1;
while (amount >= power2) {
amount -= power2;
items.emplace_back(weight * power2, value * power2);
power2 *= 2;
}
if (amount > 0) {
items.emplace_back(weight * power2, value * power2);
}
}
std::vector<int> maxValue(limitWeight + 1);
for (int index = 0; index < (int)items.size(); index++) {
for (int weight = limitWeight; weight >= 0; weight--) {
if (items[index].first <= weight) {
maxValue[weight] = std::max(maxValue[weight], maxValue[weight - items[index].first] + items[index].second);
}
}
}
std::cout << maxValue[limitWeight];
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... |