#C9824. Inventory Management System

    ID: 53960 Type: Default 1000ms 256MiB

Inventory Management System

Inventory Management System

You are required to implement an inventory management system for an e-commerce platform. The system supports three operations:

  1. ADD: Increase the stock of a product by a given amount. If the product does not exist, create it with the given quantity.
  2. REMOVE: Decrease the stock of a product by a given amount. If the removal amount is more than the current stock, set the stock to 0. If the product does not exist, do nothing.
  3. QUERY: Print the current stock of the product. If the product does not exist, print 0.

The input format is as follows:

  • The first line contains an integer (n) denoting the number of operations.
  • Each of the next (n) lines contains an operation in one of the following forms:
    • ADD product_id quantity
    • REMOVE product_id quantity
    • QUERY product_id

For each QUERY operation, output the current stock of the product on a new line.

The behavior of removal should follow the mathematical formula:

[ stock = stock - \min(stock, quantity) ]

Make sure to use the standard input and output streams for reading and writing data.

inputFormat

The first line of the input contains a single integer (n), the number of operations to be performed. Each of the following (n) lines describes an operation in one of the following three formats:

  • ADD product_id quantity
  • REMOVE product_id quantity
  • QUERY product_id

Here, product_id and quantity are integers.

outputFormat

For each QUERY operation, output a single line with the current stock of the queried product. If the queried product does not exist in the system, output 0.## sample

6
ADD 101 50
QUERY 101
ADD 101 25
QUERY 101
REMOVE 101 10
QUERY 101
50

75 65

</p>