#K73392. Stock Operations Simulation

    ID: 33965 Type: Default 1000ms 256MiB

Stock Operations Simulation

Stock Operations Simulation

You are given n products, each with an initial stock level. Your task is to simulate a series of stock operations on these products. Each operation is either an add or a remove operation. In an add operation, a specified quantity is added to a product’s stock level. In a remove operation, the specified quantity is subtracted from a product’s stock level, but the stock cannot fall below 0.

The operations are given in the following format: "op i k", where op is either add or remove, i is the 1-indexed product number, and k is the quantity to add or remove.

You should process all operations sequentially and then output the final stock level of each product. Mathematically, if \(S_i\) is the initial stock of product \(i\) and an operation updates it to \(S'_i\) then for a remove operation, we update it as:

[ S'_i = \max(0, S_i - k) \quad \text{(for remove operations)} ]

For add operations, the update is:

[ S'_i = S_i + k \quad \text{(for add operations)} ]

</p>

Output the final stock levels separated by a space.

inputFormat

The input is given from stdin and has the following format:

  1. An integer n representing the number of products.
  2. n space-separated integers representing the initial stock levels of each product.
  3. An integer m representing the number of operations.
  4. m lines follow, each line is an operation in the format: "op i k" where op is either add or remove, i is the product index (1-indexed), and k is the quantity.

outputFormat

Output the final stock levels for all products as a single line with space-separated values to stdout.

## sample
3
10 20 15
4
add 1 5
add 2 10
remove 3 5
remove 2 30
15 0 10