← Back to puzzles

003 Overburdened

Everyone who's ever played a computer RPG should be familiar with this problem: You have a large stash of valuable items, but you can't carry them all back to town. Given a list of items, their weight and their value, compute the most valuable set of items that you could carry.

For example, given the input:

healing potion,300,1
healing potion,300,1
healing potion,300,1
magic tome,900,10
enchanted shield,500,8

The expected output should be:

healing potion, healing potion, magic tome, enchanted shield

Another example—given the input:

obsidian dagger,1000,1
rusted buckler,400,6
dragonscale chestplate,800,12
golden helmet,700,2
metal skullcap,350,2

The answer should be:

obsidian dagger, dragonscale chestplate, golden helmet, metal skullcap

Good luck on your travels, brave adventurer!