After a hard day killing monsters in the dungeons of level 40, shopping time has arrived. You count all the obtained gold, you get closer to the shopkeeper of the town and look the sheet of prices...
Your character can only bring exactly four objects with him: a weapon, a helmet, an armour and an armband. Each one of these objects provides you a benefits , or points, of three types: attack points, defense points, or magic points. Your task is to write a program that, given the list of prices, decides how to invest the won gold to equip your character with objects that maximize the sum of these three types of points.
The first line contains two naturals and , where is the number of gold coins that you have and the number of objects that there are in the shop. Then, lines, every one of them following the format , where is a character that indicates the type of object (’A’, ’Y’, ’C’, ’B’), is a sequence of at most 20 uppercase letters with the name of the object, is its price in gold coins, and , and are integer numbers that indicate the points of attack, defense and magic that gives the possession of the object.
Your program must solve 30 inputs like the described ones in a time of 1 second.
Find which objects you must buy, without being more than one of each type, to maximize the sum of attack, defense and magic points; in case of being more than one optimal combination, your program must print the cheapest one. The input data will be in a way that will only exist one combination with this property.
In particular, your program must print two lines. In the first line, separated by spaces, it must print the names of the weapon, helmet, armour and armband that it has chosen, or “NOTHING” if you do not buy any object. In the second line, also separated by spaces, it must print the attack, defense and magic points that gives you the chosen combination.
Author: Unknown
Translator: Carlos Molina
Generation: 2026-01-25T11:13:26.361Z
© Jutge.org, 2006–2026.
https://jutge.org