Question DSA-GRDY-0042
MediumWhat is the output of this code?
items = [(480, 30), (400, 20), (180, 10)]
cap, total = 40, 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.
1060.0
- B.
880.0
- C.
Sign up free to see the answer and a step-by-step explanation.