#K79632. Inventory Management System

    ID: 35352 Type: Default 1000ms 256MiB

Inventory Management System

Inventory Management System

You are given an inventory management system that handles four types of operations:

  • 1 ID Name Quantity: Add a new product with the given ID, Name, and Quantity to the inventory. If a product with the same ID already exists, update its name and quantity to the new values.
  • 2 ID Quantity: Update an existing product by adding the given Quantity (which can be negative) to its current quantity.
  • 3 ID: Query and print the current quantity of the product with the given ID. If the product does not exist, print 0.
  • 4: Print the product having the highest quantity in the inventory. In case of a tie, choose the product with the smallest ID. The output should be two numbers: the ID and the quantity.

Input will be provided from standard input (stdin) and outputs should be printed to standard output (stdout). The operations are given in order, and only operations of type 3 and 4 produce output.

The formula to decide the product with the highest quantity can be expressed in \( \text{argmax}_{ID} \{ Q(ID) \} \), and in case of ties, the product with the smallest \( ID \) is chosen.

inputFormat

The first line contains a single integer \( N \) (\(1 \le N \le 10^5\)), representing the number of operations. The next \( N \) lines each contain one operation in one of the following formats:

  • 1 ID Name Quantity
  • 2 ID Quantity
  • 3 ID
  • 4

Note: The 1 command adds a product with the given ID, Name (a string without spaces) and Quantity (an integer). The 2 command updates an existing product's quantity.

Input is read from standard input (stdin).

outputFormat

For each operation of type 3, output a single line containing an integer representing the current quantity of the product with the specified ID (or 0 if it does not exist).

For each operation of type 4, output a single line containing two integers separated by a space: the ID of the product with the highest quantity and its quantity.

Output should be printed to standard output (stdout).

## sample
7
1 101 Apple 50
1 102 Banana 30
1 103 Orange 40
2 102 20
3 102
4
2 101 10
50

101 50

</p>