#K2931. Supermarket Inventory and Promotions Management

    ID: 24846 Type: Default 1000ms 256MiB

Supermarket Inventory and Promotions Management

Supermarket Inventory and Promotions Management

In this problem, you are required to simulate a supermarket's inventory management along with its promotional queries. The supermarket system supports three types of operations:

  1. Add: Increase the inventory of a given item.
  2. Remove: Decrease the inventory of an item (the inventory should not go below zero).
  3. Promote: Check if an item is under promotion.

Given (N) queries and (P) promotional items, process the queries sequentially. For every Promote query, output Yes if the queried item is in the promotional list, and No otherwise.

The inventory update operations (Add and Remove) must be simulated even though only the promotional status is used to answer Promote queries.

The update rules are as follows:

  • For an Add operation: (inventory[item] \mathrel{+}= quantity).
  • For a Remove operation: (inventory[item] = \max(inventory[item] - quantity, 0)).

Note: The promotional check is independent of the item count in the inventory.

inputFormat

The input is given via standard input (stdin) and follows this format:

N P
promo_1 promo_2 ... promo_P
query_1
query_2
...
query_N

Where:

  • (N) is the number of queries.
  • (P) is the number of promotional items.
  • The second line contains (P) strings representing the promotional items (if (P > 0)).
  • The next (N) lines each contain a query in one of the following formats:
    • Add <item> <quantity>
    • Remove <item> <quantity>
    • Promote <item>

outputFormat

For each Promote query encountered in the input, output a line to standard output (stdout) containing either Yes if the item is a promotional item, or No if it is not.## sample

7 2
MILK BREAD
Add MILK 100
Add BREAD 50
Promote MILK
Remove BREAD 30
Promote BREAD
Remove MILK 200
Promote EGGS
Yes

Yes No

</p>