#C4297. Inventory Update
Inventory Update
Inventory Update
You are given the current inventory of books along with a set of updates in the form of sales (negative numbers) or restocking (positive numbers). Each book is identified by its ISBN. Your task is to update the inventory by applying only the updates to books that are present in the initial list. After processing all the updates, only the books with a positive quantity should remain. Note that the updated quantity for each book is computed as
[ \text{inventory}(\text{isbn}) = \text{initial}(\text{isbn}) + \sum \text{updates}(\text{isbn}) ]
Print the final inventory records in lexicographical order of their ISBNs. If no books remain, output nothing.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains a single integer (n), the number of books in the initial inventory.
- The next (n) lines each contain a string and an integer separated by a space: the ISBN and the initial quantity of that book.
- The following line contains a single integer (m), the number of update operations.
- The next (m) lines each contain a string and an integer separated by a space: the ISBN and the update value (which could be negative or positive).
For example:
3 978-1-4028-9467-3 10 978-0-306-40615-7 5 978-0-306-40615-6 2 4 978-1-4028-9467-3 -3 978-0-306-40615-7 -2 978-1-4028-9467-3 1 978-0-306-40615-6 -2
outputFormat
Output the updated inventory records to standard output (stdout) in lexicographical order (sorted by ISBN). For each book with a positive quantity, print one line containing the ISBN and the updated quantity separated by a space. If no books have a positive quantity, print nothing.## sample
3
978-1-4028-9467-3 10
978-0-306-40615-7 5
978-0-306-40615-6 2
4
978-1-4028-9467-3 -3
978-0-306-40615-7 -2
978-1-4028-9467-3 1
978-0-306-40615-6 -2
978-0-306-40615-7 3
978-1-4028-9467-3 8
</p>