#C6861. Library Operations Simulation
Library Operations Simulation
Library Operations Simulation
You are given a library inventory consisting of N distinct books. Each book is identified by a unique integer ID and has a certain number of copies available initially. Then M operations are performed on the library. Each operation is represented as a pair of integers: a timestamp and an operation value.
The operation value works as follows:
- If the value is positive, it indicates that a user borrows one copy of the book with that ID.
- If the value is negative, it indicates that a user returns one copy of the book corresponding to \( |id| \).
Your task is to simulate these operations and print the final state of each book. The final state for each book should be output in ascending order of book IDs, in the following format:
Book id: borrowed X, available Y
Here, X is the total number of copies borrowed, and Y is the number of copies remaining available.
Note: It is guaranteed that all operations are valid.
inputFormat
The input is read from standard input and has the following format:
N id1 copies1 id2 copies2 ... idN copiesN M timestamp1 op1 timestamp2 op2 ... timestampM opM
Where:
- N is the number of different books.
- Each of the next N lines contains two integers: a book id and the number of copies available initially.
- M is the number of operations.
- Each of the next M lines contains two integers: a timestamp (which can be ignored for processing order) and an operation value. A positive operation value indicates a borrow, while a negative value indicates a return.
outputFormat
The output is printed to standard output. For each book (in ascending order of their IDs), print a line in the following format:
Book id: borrowed X, available Y
Where id is the book identifier, X is the total number of copies borrowed, and Y is the number of copies available.
## sample3
101 4
102 2
103 1
6
1 101
2 102
3 101
4 -101
5 101
6 -102
Book 101: borrowed 2, available 2
Book 102: borrowed 0, available 2
Book 103: borrowed 0, available 1
</p>