#C12704. Inventory Management: Update and Query

    ID: 42161 Type: Default 1000ms 256MiB

Inventory Management: Update and Query

Inventory Management: Update and Query

You are given an inventory represented as a JSON object (dictionary) and a new stock also represented as a JSON object. Your task is to update the inventory by adding the quantities from the new stock. After updating, you have to find the names of the items that have stock strictly less than a given threshold.

The problem requires you to implement two functionalities:

  • Update Inventory: For every item in the new stock, add its quantity to the existing inventory. If the item is not already present in the inventory, add it.
  • Find Low Stock Items: From the updated inventory, return a list of items whose stock is less than the threshold value.
  • </p>

    Both functions will be integrated into a program that reads inputs from stdin and prints outputs to stdout in JSON format.

    Note: All mathematical expressions (if any) should be in LaTeX format. For example, if you need to express an update, you could write it as \(\text{new_quantity} = \text{old_quantity} + \text{incoming_quantity}\).

    inputFormat

    The input consists of three lines:

    1. A JSON object representing the current inventory. The keys are product names (strings) and the values are their stock quantities (integers).
    2. A JSON object representing the new stock. The keys are product names (strings) and the values are the quantities to be added (integers).
    3. An integer representing the threshold. Only items with stock strictly less than this threshold will be considered low in stock.

    All input is provided via stdin.

    outputFormat

    The output should consist of two lines:

    1. A JSON object representing the updated inventory after processing the new stock.
    2. A JSON array (list) of product names (strings) whose stock is strictly less than the threshold. The ordering of the products in the list does not matter.

    Both outputs should be printed to stdout.

    ## sample
    {"apples": 10, "bananas": 5, "oranges": 2}
    {"apples": 5, "oranges": 3, "grapes": 7}
    5
    {"apples":15,"bananas":5,"oranges":5,"grapes":7}
    

    []

    </p>