#K66902. Airplane Seat Reservation Requests

    ID: 32523 Type: Default 1000ms 256MiB

Airplane Seat Reservation Requests

Airplane Seat Reservation Requests

You are given an airplane seating layout and a series of seat reservation requests. The layout is represented as a matrix where each element is either 0 (indicating an available seat) or 1 (indicating an already booked seat).

For each request, if the seat is available, you should book it (i.e. mark it as 1). If the seat is already booked, the request cannot be fulfilled. Your task is to count how many seat requests cannot be fulfilled.

The problem can be mathematically described as follows: Given a matrix \( A \) of size \( R \times C \) with \( A[i][j] \in \{0,1\} \) and a sequence of requests \( (r, c) \). For each request, if \( A[r][c] = 0 \), set \( A[r][c] = 1 \); otherwise, count it as an unfulfillable request. Output the total count of unfulfillable requests.

inputFormat

The input is read from standard input (stdin) in the following format:

R C
row1
row2
... 
rowR
Q
r1 c1
r2 c2
...
rQ cQ

Where:

  • R and C are integers indicating the number of rows and columns of the seating layout.
  • Each of the next R lines contains C space-separated integers (0 or 1) representing a row of seats.
  • Q is an integer representing the number of seat requests.
  • Each of the next Q lines contains two integers r and c (0-indexed) representing a seat request.

outputFormat

Output a single integer to standard output (stdout), representing the number of seat requests that could not be fulfilled.

## sample
2 2
1 1
1 1
4
0 0
0 1
1 0
1 1
4