#K85827. Theatre Seat Booking
Theatre Seat Booking
Theatre Seat Booking
You are given a theatre with \( R \) rows and \( S \) seats per row. Initially, all seats are available (denoted by 0). You will receive \( Q \) booking queries. In each query, you are given a row index (0-indexed) and a number of contiguous seats \( k \) you wish to book. The booking is successful if there exists a contiguous block of \( k \) available seats (all 0's) in that row. The seats are always booked from the leftmost available block. If the booking is successful, mark these seats as booked (set to 1) and print "true"; otherwise, print "false".
After processing all queries, output the final seating arrangement of the theatre. Each row should be printed on a new line with the seat states separated by a space.
Note: The theatre is represented as a matrix \( A \) of size \( R \times S \) where each entry \( A_{ij} \) is either 0 (available) or 1 (booked).
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains two integers \( R \) and \( S \) representing the number of rows and the number of seats per row.
- The second line contains an integer \( Q \) representing the number of booking queries.
- Each of the next \( Q \) lines contains two integers: the row index (0-indexed) and the number of contiguous seats to book.
outputFormat
For each booking query, output a line with either "true" if the booking is successful, or "false" otherwise. After processing all queries, output the final seating arrangement of the theatre: each of the \( R \) rows on a new line, with the seat values (0 or 1) separated by a single space.
## sample5 10
4
0 4
0 7
1 10
0 4
true
false
true
true
1 1 1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
</p>