#C1782. Vending Machine Simulator
Vending Machine Simulator
Vending Machine Simulator
This problem simulates a vending machine that dispenses items based on the funds provided by the user. The vending machine has a limited stock of each item. For each purchase attempt, if the provided amount is greater than or equal to the cost of the item and the item is available in stock, the machine dispenses the item and decrements its stock; otherwise, the attempt fails.
Note: If an item is not found in the machine, the attempt is considered a failure.
The condition for a successful purchase can be represented in LaTeX as follows:
[ \text{if } amount \geq cost \text{ and } stock > 0 \text{ then SUCCESS, otherwise FAIL} ]
inputFormat
The input is given via standard input (stdin) and is structured as follows:
- The first line contains an integer \(N\) representing the number of different items.
- The next \(N\) lines each contain an item's description in the format:
item_name cost stock
(separated by spaces). - The next line contains an integer \(M\) that indicates the number of purchase attempts.
- The following \(M\) lines each represent a purchase attempt in the format:
item_name amount_paid
.
outputFormat
For each purchase attempt, output a single line: either SUCCESS
if the attempt is successful or FAIL
otherwise.
4
Coke 25 100
Pepsi 35 50
Water 15 200
Juice 45 30
5
Coke 25
Water 10
Pepsi 35
Juice 60
Chocolate 50
SUCCESS
FAIL
SUCCESS
SUCCESS
FAIL
</p>