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.
- The items are given as a string of comma-separated values, with the following structure: Name, value, weight in kilograms
- You can carry a maximum of 20 kilograms
- Your program should output the names of the selected set of items (order is not important)
- If an item occurs multiple times in the input, it can also occur multiple times in the output
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!