#K37187. Vending Machine Control System
Vending Machine Control System
Vending Machine Control System
You are tasked with designing a control system for a vending machine. The system should verify if every product request can be fulfilled based on the available stock. For each test case, the system will first receive a number T, indicating the number of test scenarios in that run. For each scenario, the input begins with an integer m representing the number of products. It is followed by m lines, each containing a product identifier and its available stock. Next, an integer n denotes the number of requests. This is followed by n lines each with a product identifier and the requested quantity. The system must check, for each scenario, whether all the requested products can be dispensed in the desired quantities. A request can only be fulfilled if the product exists in stock and its available quantity is at least the requested amount. After processing all requests for a scenario, print "Possible" if every request is fulfilled; otherwise, print "Not Possible".
The constraints ensure that the process is straightforward and involves simple simulation.
In mathematical terms, for a given product with initial stock S and a requested quantity Q, it must hold that ( S \ge Q ). After a request, the stock is updated to ( S - Q ). This condition must hold true for all requests in the test case.
inputFormat
The input is read from standard input (stdin). The first line contains an integer T, the number of scenarios. For each scenario, the input is as follows:
- An integer m representing the number of products.
- m subsequent lines, each containing two space-separated integers: product_id and available_stock.
- An integer n representing the number of requests.
- n subsequent lines, each containing two space-separated integers: product_id and requested_quantity.
outputFormat
For each scenario, output a single line to standard output (stdout) with the string "Possible" if all product requests can be fulfilled, or "Not Possible" otherwise.## sample
2
3
1 5
2 10
3 7
2
1 3
2 5
1
1 8
1
1 10
Possible
Not Possible
</p>