#K91567. Bakery Sales vs Orders Difference
Bakery Sales vs Orders Difference
Bakery Sales vs Orders Difference
This problem simulates a bakery's daily operations by tracking both sales and orders for each bakery item. You are given an integer N representing the number of log entries and an integer M representing the number of distinct items sold by the bakery. Following this, there are M lines where each line contains an item name and its price per unit. Then, there are N subsequent lines describing log entries. Each log entry is in the format:
operator item_name quantity
where the operator is either '+' (indicating a sale) or '-' (indicating an order). The goal is to compute the revenue difference for each item using the formula:
$$\text{difference} = (\text{sales quantity} \times \text{price}) - (\text{order quantity} \times \text{price})$$
Finally, output the result for each item in lexicographical order by comparing item names.
inputFormat
The input is read from stdin and has the following format:
- The first line contains two integers N and M, separated by a space.
- The next M lines each contain a string and an integer, representing the item name and its price per unit.
- The following N lines each contain a log entry. Each log entry is in the format:
operator item_name quantity
, whereoperator
is either '+' or '-'.
outputFormat
The output should be printed to stdout. It consists of M lines where each line contains an item name and its computed revenue difference (sales revenue minus orders revenue), separated by a space. The items must be listed in lexicographical order.
## sample5 2
croissant 5
muffin 3
+ croissant 20
- croissant 10
+ muffin 5
- muffin 8
+ croissant 30
croissant 200
muffin -9
</p>