#C6739. Total Price Calculation with Discounts
Total Price Calculation with Discounts
Total Price Calculation with Discounts
You are given a list of items, each with a name and a price (in cents), and a set of promotional discounts. Each promotion is provided as a percentage discount for a given item name. For each item in the list, if there is a corresponding discount (matched in a case sensitive manner), apply the discount to the price. Otherwise, charge the full price.
The total price is the sum of all discounted item prices. The final result should be rounded to the nearest whole cent. If no items are given, output 0.
Formula: For an item with price \(P\) and discount \(d\) (in percent):
\( \text{Discounted Price} = P \times \left(1 - \frac{d}{100}\right) \)
Sum over all items and round the final result to obtain the answer.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- An integer \(N\), representing the number of items.
- \(N\) lines follow, each line contains a string and an integer separated by space: the item's name and its price (in cents).
- An integer \(M\), representing the number of promotions.
- \(M\) lines follow, each line contains a string and an integer separated by space: the item's name and its discount percentage.
Note: If there are no items, \(N = 0\) and the promotions part will still be provided (as \(M = 0\) or some value, but it will not affect the result).
outputFormat
Output a single integer representing the total price (in cents) after applying the discounts. The result should be rounded to the nearest whole cent and printed to standard output (stdout).
## sample0
0
0