#C11725. Inventory Order Processing
Inventory Order Processing
Inventory Order Processing
You are given an inventory of n products. The initial stock for each product is given as a list. You will then receive m orders. Each order is in the form of a pair (product index, desired quantity).
For each order, if the current inventory for the specified product is sufficient, i.e. if \(a_i \ge q_i\) where \(a_i\) is the current stock and \(q_i\) is the desired quantity, then the order is processed and the stock is reduced accordingly. Otherwise, the order is rejected and the inventory remains unchanged.
After processing all orders, output the result of each order – either "Order fulfilled" or "Order rejected" – each on its own line, followed by a final line that shows the updated stock quantities separated by spaces.
inputFormat
The input is given via stdin in the following format:
n q1 q2 ... qn m p1 d1 p2 d2 ... p_m d_m
where:
n
is the number of products.q1, q2, ..., qn
represent the initial quantities of each product.m
is the number of orders.- Each of the next
m
lines contains two integers:p
(the product index, 0-indexed) andd
(the desired quantity).
outputFormat
The output should be printed to stdout and must consist of exactly m+1
lines:
- The first
m
lines should each contain either "Order fulfilled" or "Order rejected", depending on whether that order was processed. - The last line should contain the updated quantities of all products, separated by a single space.
2
5 10
3
0 5
1 9
0 1
Order fulfilled
Order fulfilled
Order rejected
0 1
</p>