#K9066. Inventory Management

    ID: 37802 Type: Default 1000ms 256MiB

Inventory Management

Inventory Management

You are managing the inventory of a store. Initially, there are n items with given stock levels. You will be given a sequence of q operations to process. There are three types of operations:

  • DELIVERY: Increase the stock level of an item by a given quantity.
  • SALE: Decrease the stock level of an item by a given quantity.
  • QUERY: Output the current stock level of a specified item.

The operations are processed in the order they appear. Note that item indices are 1-based. Simulate the operations and provide the output for every QUERY.

Mathematically, if the initial stock level of the i-th item is \( S_i \), then a DELIVERY operation adds a quantity \( q \) resulting in \( S_i \leftarrow S_i + q \), and a SALE operation subtracts a quantity \( q \) resulting in \( S_i \leftarrow S_i - q \). A QUERY simply prints \( S_i \).

inputFormat

The input is given in the following format:

n q
s1 s2 ... sn
operation_1
operation_2
...
operation_q

Where the first line contains two integers \( n \) and \( q \). The second line contains \( n \) integers which represent the initial stock levels of each item. Each of the next \( q \) lines contains an operation in one of the following formats:

  • DELIVERY id quantity
  • SALE id quantity
  • QUERY id

Note: Items are 1-indexed.

outputFormat

For each QUERY operation, output the current stock level of the specified item on a new line.

## sample
5 6
10 20 30 40 50
DELIVERY 2 10
SALE 3 5
QUERY 2
SALE 5 10
DELIVERY 1 5
QUERY 5
30

40

</p>