Gamified challenge · Greedy by ratio
Each item is [weight, value] (weight in kg, at least 1). The hold carries at most cap kg. You may take any fraction of an item: x kg of it is worth value × x / weight.
Write maxValue(items, cap) that returns the largest total value that fits, as a decimal number. Answers within 1e-5 of the right value are accepted. For [[10, 60], [20, 100], [30, 120]] and cap = 50 the answer is 240.0: all of the first two and 20 kg of the third.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google