#K39292. Reserve Consecutive Seats
Reserve Consecutive Seats
Reserve Consecutive Seats
You are given a seating plan represented as a matrix of size \( r \times c \), where each element is either 0 or 1. A value of 0 indicates an available seat, and 1 indicates that the seat is already reserved. Your task is to reserve \( k \) consecutive seats in the specified row (0-indexed).
The reservation should follow these rules:
- If the requested row index is invalid, or if there is no block of \( k \) consecutive available seats (i.e. 0's) in that row, output
Cannot reserve seats
. - If successful, update the seating plan by marking the reserved seats (change from 0 to 1) and output the updated seating plan.
Note: All indices are 0-indexed.
inputFormat
The input is given through standard input (stdin) in the following format:
r c row_1 (c space-separated integers) row_2 ... row_r k r_index
Here, \( r \) is the number of rows and \( c \) is the number of columns in the seating plan. Each of the next \( r \) lines contains \( c \) integers (either 0 or 1). Finally, \( k \) is the number of consecutive seats to reserve, and \( r_index \) is the row in which to make the reservation.
outputFormat
If the reservation is successful, output the updated seating plan to standard output (stdout). The output should have \( r \) lines, each containing \( c \) space-separated integers representing the seating plan after reservation.
If the reservation fails, output exactly the following message:
Cannot reserve seats## sample
4 5
0 0 0 1 1
1 0 0 0 0
0 1 1 0 0
0 0 0 0 0
2 3
0 0 0 1 1
1 0 0 0 0
0 1 1 0 0
1 1 0 0 0
</p>