#C7244. Warehouse Order Processing Simulation

    ID: 51094 Type: Default 1000ms 256MiB

Warehouse Order Processing Simulation

Warehouse Order Processing Simulation

This problem simulates the process of handling orders for a warehouse inventory management system. There are n products, each with an initial quantity. You will receive m orders where each order consists of a product ID and a requested quantity. For each order, if the stock available is greater than or equal to the requested quantity, subtract the requested quantity; otherwise, set the stock to zero.

The process can be formulated as follows:

For each order \((p, q)\), let \(s_p\) be the stock of product \(p\). Then, \[ s_p = \begin{cases} s_p - q, & \text{if } s_p \ge q, \\ 0, & \text{otherwise.} \end{cases} \]

After processing all orders, print the final quantities of all products.

inputFormat

The input is given via standard input (stdin) in the following format:

  1. An integer n representing the number of products.
  2. A line with n space-separated integers representing the initial quantities of the products.
  3. An integer m representing the number of orders.
  4. m lines follow, each containing two space-separated integers, the product ID (1-indexed) and the quantity ordered.

outputFormat

Output a single line containing n space-separated integers which represent the final quantities of the products after processing all orders.

## sample
4
10 20 30 40
3
1 5
2 25
3 10
5 0 20 40

</p>