#K96187. Inventory Management

    ID: 39031 Type: Default 1000ms 256MiB

Inventory Management

Inventory Management

You are given a list of products with their initial quantities in stock and a series of transactions that either add to or remove from these quantities. Your task is to process these transactions and compute the final quantity of each product.

For a given product, if the initial quantity is \(Q_i\) and a transaction changes its quantity by \(\Delta\), the new quantity becomes \(Q_i + \Delta\). Note that the product indices are 1-indexed.

inputFormat

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

n
q1 q2 ... qn
m
p1 d1
p2 d2
... 
p_m d_m

where:

  • n is an integer representing the number of products.
  • q1, q2, ..., qn are the initial quantities of the products.
  • m is an integer representing the number of transactions.
  • Each of the next m lines contains two integers, p (the 1-indexed product index) and d (the quantity change in that transaction, which could be positive or negative).

outputFormat

The output, written to standard output (stdout), is a single line containing n integers separated by spaces. These integers represent the final quantities of the products in order.

## sample
4
100 200 150 175
6
1 -50
2 120
3 -30
4 70
1 20
3 -50
70 320 70 245