#C3804. Library Management System

    ID: 47272 Type: Default 1000ms 256MiB

Library Management System

Library Management System

You are given a library system where each book is represented by its title and the number of available copies.

You need to implement a system that processes various operations on the library. The operations are:

  • borrow <title>: Decrease the book count by one if it is available (i.e. number of copies > 0) and output Borrowed successfully. If the book is not available (including if the title does not exist in the library), output Book not available.
  • return <title>: Increase the book count by one. If the book does not already exist in the library, add it with count 1. Always output Returned successfully.
  • report: Output a report of all books in the library, sorted in lexicographic order by the book title. The report should be printed in one line with each book represented as title:count and each pair separated by a space.

Internally, if you let \( b(t) \) be the number of copies for a book with title \( t \), then for a borrow operation, you must check that \( b(t) > 0 \) to allow borrowing.

inputFormat

The input is read from standard input and has the following format:

  1. An integer N representing the number of books initially in the library.
  2. N lines follow, each containing a book title (a single word without spaces) and an integer indicating the number of copies available, separated by a space.
  3. An integer Q representing the number of operations.
  4. Q lines follow, each representing an operation. Each operation is one of the following formats:
    • borrow <title>
    • return <title>
    • report

outputFormat

Output to standard output. For each operation, output a line based on the following:

  • For borrow operations, print either Borrowed successfully or Book not available.
  • For return operations, print Returned successfully.
  • For report operations, print a single line listing each book in the format title:count separated by a space, sorted by title in lexicographic order.
## sample
2
BookA 2
BookB 0
5
borrow BookA
borrow BookB
return BookA
return BookC
report
Borrowed successfully

Book not available Returned successfully Returned successfully BookA:2 BookB:0 BookC:1

</p>