Question DSA-GRDY-0009
MediumWhat is the output of this code?
items = [(60, 10), (100, 20), (120, 30)]
cap, total = 50, 0.0
for v, w in sorted(items, key=lambda x: x[0] / x[1], reverse=True):
take = min(w, cap)
total += v * take / w
cap -= take
print(total)
- A.
240.0
- B.
180.0
- C.
Sign up free to see the answer and a step-by-step explanation.