Drink Responsibly
Time limit1sMemory limit256 MB
Decide whether whole numbers of up to eight drinks can total exactly m in cost and u in alcohol, and print the lexicographically smallest purchase.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
The University of Lagado runs a beer tasting during Fresher's week. For safety the university caps how much money one student may spend, and each student sets a personal limit on the alcohol they will drink that night.
Drinks are served in one of three sizes: a litre, half a litre, or a third of a litre. One unit of alcohol is the amount contained in one litre of a drink of strength 1 percent. A drink of strength percent served in a size of litres therefore holds units.
A student wants to spend all of their money, down to the last coin, and drink exactly units of alcohol. No more and no less. Any drink may be bought any number of times, including none. Decide whether such a purchase exists, and if it does, print what to buy and how many of each.
Input
The first line holds three values.
- (), the money available, written to two decimal places.
- (), the number of units aimed for, written to one decimal place.
- (), the number of different drinks on sale.
Each of the next lines holds four values separated by single spaces.
- The name of the drink, up to 20 lowercase latin letters. The names are distinct.
- Its strength, an integer percentage between 0 and 100.
- Its size,
1/1for a litre,1/2for half a litre,1/3for a third of a litre. - Its cost, a real number between 0.00 and 10.00 written to two decimal places.
Output
If no purchase spends exactly and delivers exactly units, print one line holding IMPOSSIBLE.
Otherwise print one line for every drink bought, in the order the drinks appear in the input, giving the name and then the number bought, separated by one space. A drink bought zero times is not printed.
Several purchases may work. Write for the number bought of the -th drink of the input, so that a purchase is the sequence , and print the purchase that comes first in lexicographic order: take the smallest , among those the smallest , and so on to the end.
Because is at least 0.01, any purchase that exists buys at least one drink, so the output is never empty.