#K45347. Library Inventory Management

    ID: 27733 Type: Default 1000ms 256MiB

Library Inventory Management

Library Inventory Management

This problem simulates a library inventory management system. You are given n books with their initial stock levels, and the system must process m operations. There are two types of operations:

  • Q x: Query the available stock of book x.
  • B x y: Borrow y copies of book x. The operation succeeds if there are at least y copies available; otherwise, it fails.

After each operation, output the result. For a query, output the current stock of the book. For a borrow operation, output Success if the transaction is completed, or Fail if not enough copies are available. The operations must be processed sequentially, updating the stock levels accordingly.

Note: All formulas or numbers used in explanation conform to the format \(n, m, stock\) etc.

inputFormat

The input is provided as standard input (stdin) with multiple lines:

  • The first line contains two space-separated integers \(n\) and \(m\): the number of books and the number of operations respectively.
  • The second line contains \(n\) space-separated integers representing the initial stock levels for each book.
  • The following \(m\) lines each contain an operation in one of the following formats:
    • Q x: Query the stock for book \(x\).
    • B x y: Borrow \(y\) copies of book \(x\).

outputFormat

For each operation, output a single line:

  • If the operation is a query (Q x), output the current stock of book \(x\).
  • If the operation is a borrow (B x y), output Success if the operation is successful and Fail otherwise.

All outputs should be printed to the standard output (stdout), one result per line.

## sample
5 6
10 5 3 0 7
Q 2
B 2 3
Q 2
B 3 4
Q 3
B 5 7
5

Success 2 Fail 3 Success

</p>