#K7121. Final Prices Calculator
Final Prices Calculator
Final Prices Calculator
You are given a set of discount rules and a list of items. Each discount rule is represented by a threshold and a discount percentage. An item qualifies for a discount rule if its quantity is greater than or equal to the threshold. For each item, the applicable discount is the highest discount percentage among the rules it qualifies for.
The final price of an item is calculated as:
\( \text{final price} = \text{quantity} \times \left(1 - \frac{\text{discount}}{100} \right) \)
Round the final price to two decimal places. If an item does not qualify for any discount rule, its final price is equal to its quantity (i.e. no discount is applied).
inputFormat
The input is read from standard input (stdin) and has the following format:
- An integer
R
representing the number of discount rules. R
lines follow, each containing two numbers: the threshold t (an integer) and the discount percentage d (a float), separated by space.- An integer
N
representing the number of items. N
lines follow, each containing an item name (a string without spaces) and its quantity (an integer), separated by space.
outputFormat
For each item, output its name and the final price (rounded to two decimals) on a separate line. The order of the items in the output should be the same as in the input.
## sample3
5 20.0
10 30.0
15 50.0
4
bananas 12
apples 5
oranges 20
grapes 3
bananas 8.4
apples 4.0
oranges 10.0
grapes 3.0
</p>