#K7161. Inventory Management System

    ID: 33570 Type: Default 1000ms 256MiB

Inventory Management System

Inventory Management System

You are required to build an inventory management system for a retail store. The system handles inventory for N different products. Initially, you are given the quantities for each product. Then, you must process a series of operations on the inventory. There are three types of operations:

  • ADD X Y: Increase the quantity of product X by Y.
  • REMOVE X Y: Decrease the quantity of product X by Y, but ensure that the quantity never goes below 0.
  • STOCK X: Report the current quantity of product X.

Implement a program that reads input from standard input (stdin) and prints the output to standard output (stdout) as described in the input and output sections.

inputFormat

The input is given from standard input (stdin) with the following format:

  1. The first line contains an integer \(N\), the number of products.
  2. The second line contains \(N\) space-separated integers representing the initial quantities of products numbered from 0 to \(N-1\).
  3. The third line contains an integer \(M\), which is the number of operations to perform.
  4. The next \(M\) lines each contain a single operation in one of the following formats:
    • \(\texttt{ADD X Y}\)
    • \(\texttt{REMOVE X Y}\)
    • \(\texttt{STOCK X}\)

outputFormat

For every \(\texttt{STOCK}\) operation encountered, print the current quantity of the specified product on a new line, in the order the \(\texttt{STOCK}\) operations are processed.

## sample
5
10 20 30 40 50
6
ADD 2 10
REMOVE 3 50
STOCK 2
REMOVE 4 10
STOCK 4
STOCK 1
40

40 20

</p>