#C7941. Inventory Management

    ID: 51868 Type: Default 1000ms 256MiB

Inventory Management

Inventory Management

You are given an initial inventory of widgets and a series of operations to perform on the inventory. The operations include:

  • add: Add a new widget with a provided id, description, and quantity.
  • remove: Remove a widget by its id.
  • update: Update the quantity of an existing widget identified by its id.
  • summary: Generate a summary report of the current inventory.

The summary report must contain:

  1. The total number of widgets.
  2. The total quantity of all widgets.
  3. A list of widget descriptions sorted in lexicographical order.

Your task is to process the given operations in order and then output the summary report immediately after the summary command is encountered (which will always be the last command).

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. An integer n representing the number of initial inventory items.
  2. n lines follow, each containing three values separated by spaces: a string id, a string description (without spaces), and an integer quantity.
  3. An integer m representing the number of operations.
  4. m lines follow, each describing an operation. The operation commands can be one of the following formats:
    • add id description quantity
    • remove id
    • update id quantity
    • summary

outputFormat

The output is printed to standard output (stdout) and should consist of three lines:

  1. The first line contains an integer representing the total number of widgets after processing all operations.
  2. The second line contains an integer representing the total quantity of all widgets.
  3. The third line contains the widget descriptions sorted in lexicographical order, separated by a single space. If there are no widgets, the third line should be empty.
## sample
1
W1 Widget_A 10
2
add W2 Widget_B 5
summary
2

15 Widget_A Widget_B

</p>