#C5975. Warehouse Order Processing Simulation

    ID: 49683 Type: Default 1000ms 256MiB

Warehouse Order Processing Simulation

Warehouse Order Processing Simulation

This problem simulates a warehouse order processing system. You will be given a series of commands, each representing an operation related to stock management or order processing for various items. The commands are as follows:

  • stock X k: Increase the stock of item X by k units. If the item does not exist in the stock, it is added.
  • order X k: Place an order for k units of item X. Regardless of the available stock, the order quantity is added to the total orders for that item. However, the available stock is decreased by the minimum of the current stock and the order quantity.
  • restock X k: Increase the available stock of item X by k units. This command is similar to stock but may occur after some orders.
  • end: Indicates the end of the command sequence.

Your task is to process the commands and then output the total ordered quantity for each item. The output must be sorted by the item name in ascending order.

In mathematical notation, let \(T_X\) denote the total order quantity for item \(X\), then for each command \(c\):

\[ T_X = \sum_{\text{order commands for } X} k, \]

where \(k\) is the order quantity specified in the command.

inputFormat

The input consists of multiple lines. Each line represents a command as described above. The input is terminated by a line containing a single word "end".

Note: All quantities are positive integers and item names are case-sensitive strings without spaces.

outputFormat

For each item that has been ordered at least once, output a line containing the item name and the total ordered quantity separated by a space. The items must be output in alphabetical order.

## sample
stock A 100
order A 50
order A 75
restock A 30
order A 50
order B 10
stock B 100
order B 20
end
A 175

B 30

</p>