#K93472. Update Book Inventory
Update Book Inventory
Update Book Inventory
You are given a series of operations to update a book inventory. Each operation is represented as a pair (book_id, count) where count can be positive, zero, or negative. For each operation, the inventory should be updated according to the formula:
$$inventory[book\_id] = inventory[book\_id] + count$$
If a book_id is not present in the inventory, it should be added with the given count.
Your task is to compute the final inventory after performing all operations. Finally, output the inventory items sorted by book_id in ascending order, each on a separate line with the book_id and the final count separated by a space.
inputFormat
The input is provided via standard input (stdin) with the following format:
- The first line contains an integer N, the number of operations.
- The next N lines each contain two space-separated integers representing a book_id and a count.
outputFormat
Output the final inventory to standard output (stdout). For each book in the inventory, print a line with the book_id and the final count separated by a space. The output should be sorted by book_id in ascending order.
## sample5
101 5
102 7
101 -2
103 10
102 -3
101 3
102 4
103 10
</p>