Frank has made it to a Food Basics! Without causing property damage exceeding $1000! There he meets Jeffrey (since grocery stores don't have roads) and he agrees to help Frank buy some apples. You must also help Frank buy some apples.
The Food Basics that Frank is visiting has
Frank also likes some types of apples more than others, and he assigns a value
Jeffrey and Frank would like to buy apples in such a way so that he can maximize the total sum of all values of apples. Help them calculate it!
Input Specification
The first line of input will contain the integers
The next E V A B
, where
It is guaranteed that the apples will be given in alphabetical order by name. Apple names will be strings of Latin characters, without spaces. Each apple name will not exceed
Output Specification
First, print out the maximum value sum of apples that Frank can buy. Then, for each type of apple (in alphabetical order), print out a line with the apple type and the number of apples Frank should buy to maximize value.
If there are multiple answers, print any of them.
Sample Input
3 250 250
gala 500 20 4
goldendelicious 450 1 25
green 380 13 4
Sample Output
10110
gala 1
goldendelicious 7
green 17
Sample Explanation
In order to maximize the value of apples purchased, Jeffrey and Frank should buy seven goldendelicious
apples, 17 green
apples, and 1 gala
apple. The sum of the values of the apples they buy will be
Comments
If in order to maximize the value of their apples, they shouldn't buy one of the apples, should you include that in your output? For example, if they needed 0 gala apples, 7 golden delicious, and 17 green would the output be:
For those who still care
Yes, I believe so.