#K88527. Retail Store Inventory Management
Retail Store Inventory Management
Retail Store Inventory Management
A retail store utilizes a digital inventory system to manage its products. Each product has a unique ID, a category, a current quantity, and a restock threshold. Whenever a customer makes a purchase, the quantity of the product is decreased. If the new quantity is less than or equal to the restock threshold, the system generates an alert for that product to be restocked.
Your task is to implement a program that reads the inventory details and a sequence of purchases from standard input, processes the orders, and outputs the list of product IDs that need to be restocked. The list should be sorted in ascending order. If no products need to be restocked, output "No items need to be restocked".
The restock condition can be mathematically defined as follows: for any product with an updated quantity q and restock threshold t, an alert is generated if:
[ q \leq t ]
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer n (1 ≤ n ≤ 100), the number of items in the inventory.
- The next n lines each contain details of an item in the format:
ID category quantity threshold
, where: ID
is a positive integer (1 ≤ ID ≤ 1000),category
is a string of lowercase letters,quantity
is a positive integer (1 ≤ quantity ≤ 100), andthreshold
is a positive integer (1 ≤ threshold ≤ 100).- The next line contains an integer m (0 ≤ m ≤ 1000), the number of purchases.
- The next m lines each describe a purchase in the format:
ID purchased_quantity
.
outputFormat
The program should output the list of product IDs that require restocking, sorted in ascending order, on a single line with a space separating the IDs. If no items require restocking, output exactly:
No items need to be restocked## sample
4
101 electronics 50 20
102 kitchen 30 10
103 toys 15 5
104 appliances 25 10
3
101 35
102 25
103 11
101 102 103