#C10472. Warehouse Inventory Management

    ID: 39681 Type: Default 1000ms 256MiB

Warehouse Inventory Management

Warehouse Inventory Management

You are tasked with implementing a warehouse inventory management system. In this system, each warehouse holds some stock of various products. The system needs to support two operations:

  • transfer: Transfer a certain quantity of a product from one warehouse to another.
  • checkStock: Query the current stock of a product in a specified warehouse.

The transfer operation should only succeed if the source warehouse has at least the required quantity. Otherwise, it should fail. Note that if an invalid warehouse or product is given, the operations are expected to fail (for a transfer, return false; for a checkStock, return -1).

The logic can be informally described with the condition: $$\text{If } stock[source][product] \geq quantity \text{ then perform transfer, otherwise fail.}$$

Your implementation must read the input from stdin and output the results to stdout for each operation.

inputFormat

The input is read from standard input with the following format:

  1. The first line contains two integers W and P, representing the number of warehouses and the number of products respectively.
  2. The second line contains W space-separated integers, which are the warehouse IDs.
  3. The third line contains P space-separated strings, which are the names of the products.
  4. The next W lines each contain P space-separated integers representing the initial stock for each product in the corresponding warehouse.
  5. The following line contains an integer Q representing the number of operations.
  6. The next Q lines each describe an operation in one of the following formats:
    • transfer sourceWarehouse targetWarehouse product quantity
    • checkStock warehouse product

All numeric values are integers. Product names are strings without spaces.

outputFormat

For each operation, output the result on a separate line to standard output:

  • For a transfer operation, output True if the transfer is successful or False otherwise.
  • For a checkStock operation, output the current stock (an integer) of the specified product at the given warehouse, or -1 if the warehouse or product is invalid.
## sample
2 2
101 102
apple banana
10 5
3 8
6
transfer 101 102 apple 5
checkStock 101 apple
checkStock 102 apple
transfer 101 102 apple 20
transfer 102 101 banana 4
checkStock 101 banana
True

5 8 False True 9

</p>