#C4975. Compute Remaining Inventory

    ID: 48572 Type: Default 1000ms 256MiB

Compute Remaining Inventory

Compute Remaining Inventory

You are given the initial inventory of products in a store and a list of sales transactions. Your task is to compute the remaining inventory for each product after all the sales are processed. For each product, if the initial quantity is \( Q_{initial} \) and the total quantity sold is \( S \), then the remaining quantity \( Q_{remaining} \) is given by:

\( Q_{remaining} = Q_{initial} - S \)

Note that a product may have multiple sales transactions. Finally, you must output the remaining inventory for each product in alphabetical order. The input is given via standard input (stdin) and the output should be written to standard output (stdout).

inputFormat

The input is read from standard input and has the following format:

  • The first line contains an integer \( n \) denoting the number of products.
  • The next \( n \) lines each contain a string and an integer, representing a product name and its initial quantity.
  • The next line contains an integer \( m \) denoting the number of sales transactions.
  • The following \( m \) lines each contain a string and an integer, representing a product name and the quantity sold in that transaction.

outputFormat

Output the remaining inventory for each product. For each product output a single line with the product name followed by its remaining quantity, separated by a space. The products must be listed in alphabetical order.

## sample
4
apple 100
banana 150
orange 120
pear 90
5
apple 30
banana 50
orange 30
pear 40
banana 20
apple 70

banana 80 orange 90 pear 50

</p>