이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import sys
def main():
read = sys.stdin.readline
s, n = (int(i) for i in read().split())
values = []
weights = []
quantities = []
sorted_values = []
for index in range(n):
v_i, w_i, k_i = (int(i) for i in read().split())
values.append(v_i)
weights.append(w_i)
quantities.append(k_i)
sorted_values.append((v_i / w_i, index))
sorted_values.sort(reverse=True)
curr_weight = 0
curr_total = 0
for i in range(len(sorted_values)):
_, idx = sorted_values[i]
value = values[idx]
weight = weights[idx]
quantity = quantities[idx]
remaining_weight = s - curr_weight
quantity_to_grab = min(remaining_weight // weight, quantity)
curr_total += quantity_to_grab * value
curr_weight += quantity_to_grab * weight
print(curr_total)
if __name__ == '__main__':
main()
# | 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... |