#C2501. Cinema Ticket Distribution

    ID: 45825 Type: Default 1000ms 256MiB

Cinema Ticket Distribution

Cinema Ticket Distribution

You are required to simulate an automated ticket distribution system for a cinema. The cinema has multiple screens. Each screen has a specific number of seats and some seats may already be reserved. For each reservation request, assign the earliest available seat (i.e. the smallest seat number that is not yet reserved). If no seat is available on the requested screen, output a message indicating the reservation cannot be processed.

Note on seat numbering: Seats are numbered consecutively from 1 up to the total number of seats available in that screen.

The solution must read input from standard input (stdin) and write the output to standard output (stdout).

inputFormat

The input is given via stdin. The format is as follows:

S
screen_id1 total_seats1 R1
[reserved_seat1 reserved_seat2 ... reserved_seatR1]   // This line appears only if R1 > 0
...
screen_idS total_seatsS RS
[reserved_seat1 reserved_seat2 ... reserved_seatRS]   // This line appears only if RS > 0
P
name1 screen_id_for_request1
name2 screen_id_for_request2
...
nameP screen_id_for_requestP

Here, S is the number of screens. For each screen, screen_id is its identifier, total_seats is the total number of seats in that screen, and R is the count of already reserved seats followed (if R > 0) by a line with R space-separated integers indicating reserved seat numbers. Then, P is the number of reservation requests; each request consists of a person’s name and the screen_id they want to book.

outputFormat

For each reservation request, output a single line. If a seat is available, output the booking in the format:

name seat_number

If no seat is available, output:

Sorry, name

where name is the person’s name.

## sample
1
1 5 0
5
Alice 1
Bob 1
Charlie 1
Dave 1
Eve 1
Alice 1

Bob 2 Charlie 3 Dave 4 Eve 5

</p>