#K35662. Warehouse Inventory Management

    ID: 25582 Type: Default 1000ms 256MiB

Warehouse Inventory Management

Warehouse Inventory Management

This problem simulates a warehouse inventory management system. The system processes three types of commands: RECEIVE, ORDER, and REPORT. When a RECEIVE command is encountered, the program reads product details and adds the quantity to the inventory. For an ORDER command, the program attempts to fulfill the order from the available stock; if insufficient, the remaining quantity is recorded as an unmet order. Finally, when a REPORT command is given, the program outputs a report detailing each product's ID, name, current stock, and unmet orders in lexicographical order of product IDs.

The mechanics can be mathematically described as follows:

Let \( inventory(p) \) be the current stock of product \( p \) and \( order(p) \) be an order request for \( p \). When an order \( q \) is placed,

\[ \text{if } inventory(p) \ge q, \quad inventory(p) \leftarrow inventory(p) - q, \quad unmet(p)=0; \quad \text{otherwise, } unmet(p) \leftarrow q - inventory(p) \text{ and } inventory(p) \leftarrow 0. \]

Your task is to implement this simulation, processing input from stdin and outputting the final report to stdout.

inputFormat

The input is provided via stdin and consists of several lines. The commands are:

  • RECEIVE: Followed by one or more lines each containing: product_id name quantity.
  • ORDER: Followed by one or more lines each containing: product_id quantity.
  • REPORT: Indicates that no further input lines will be processed and the program should produce a report.

For example:

RECEIVE
P001 Widget 10
P002 Gadget 5
ORDER
P001 12
P003 2
REPORT

outputFormat

The output should be printed to stdout and consist of a report with one line per product. Each line must follow this format:

Product ID: <id>, Name: <name>, Stock: <stock>, Unmet Orders: <unmet>

The products must be listed in lexicographical order based on their product IDs.

## sample
RECEIVE
P001 Widget 10
P002 Gadget 5
REPORT
Product ID: P001, Name: Widget, Stock: 10, Unmet Orders: 0

Product ID: P002, Name: Gadget, Stock: 5, Unmet Orders: 0

</p>