#C7862. Book Reservation System

    ID: 51780 Type: Default 1000ms 256MiB

Book Reservation System

Book Reservation System

This problem simulates a simple book reservation system. There are N books available and M patrons eligible to reserve them. Each book is uniquely identified by its ISBN. The system processes R reservation attempts in order. For each attempt, a patron provides their ID and the ISBN of the book they want to reserve. A reservation is successful if and only if:

  • The ISBN exists in the list of available books.
  • The book has not been reserved by any other patron previously.

If both conditions are met, the reservation is marked as Success and that book is no longer available for future reservations; otherwise, the attempt is Rejected.

Mathematically, if we denote by \(B\) the set of available book ISBNs and by \(R_i\) the reservation attempts in order, then the outcome for attempt \(i\) is:

[ \text{result}_i = \begin{cases} Success, & \text{if } book_i \in B \text{ and } book_i \text{ is not reserved before}, \ Rejected, & \text{otherwise.} \end{cases} ]

inputFormat

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

  1. The first line contains two integers N and M — the number of books and the number of patrons respectively.
  2. The second line contains N space-separated strings, each representing the ISBN of a book.
  3. The third line contains an integer R — the number of reservation attempts.
  4. Each of the next R lines contains two space-separated strings: the patron ID and the ISBN of the book they wish to reserve.

outputFormat

For each reservation attempt, print a single line to STDOUT with either Success or Rejected based on whether the reservation is accepted according to the rules.

## sample
4 3
978-1-4028-9462-6 9780306406157 978-0-201-63361-0 0131103628
5
P1 978-1-4028-9462-6
P2 9780306406157
P3 978-0-201-63361-0
P1 978-0-201-63361-0
P2 978-1-4028-9462-6
Success

Success Success Rejected Rejected

</p>