#K34842. Total Revenue Calculation for Sales Events
Total Revenue Calculation for Sales Events
Total Revenue Calculation for Sales Events
You are given a series of sales events. For each event, you must compute the total revenue generated for a specific set of product IDs. The revenue for a product is calculated as the total units sold of that product during the event.
For each event, the input is given as follows:
- An integer n representing the number of records for that event.
- Followed by n lines each containing two integers pi and ui where pi is the product ID and ui denotes units sold.
- An integer k representing the number of product queries.
- Followed by a single line with k space-separated integers, each denoting a product ID you need to query.
Your task is to calculate, for each event, the total revenue for each queried product ID. If a product did not record any sales during an event, its revenue is considered to be 0.
Note: In this problem, revenue is simply the sum of units sold.
The mathematical operation for each product can be expressed in LaTeX as:
$$\text{Revenue}(p) = \sum_{(p_i,u_i) \in \text{Event}} \mathbb{1}_{\{p_i = p\}} \times u_i $$inputFormat
The input is read from stdin
:
The first line contains an integer t, the number of events. For each event: The first line contains an integer n, the number of sale records. The next n lines each contain two space-separated integers pi and ui. The following line contains an integer k, the number of product queries. The next line contains k space-separated integers representing the queried product IDs.
outputFormat
For each event, output a single line containing k space-separated integers representing the total revenue for each queried product ID in the order they were queried. The output is written to stdout
.
2
5
1001 200
1002 300
1001 150
1003 400
1002 250
3
1001 1002 1003
4
1010 500
1009 600
1010 450
1008 700
2
1010 1008
350 550 400
950 700
</p>