The Cinema Layout#13054

The Cinema Layout (Editorial)

Because the booked seats are consecutive, we only need to determine the row number of the first seat and the row number of the last seat. All rows between them will be fully or partially occupied.

  • The first seat is .

  • The last seat is .

To find the 1-indexed row number of any given seat , we divide by the number of seats per row and round up: \lceil \frac{x}{m} \rceil.

In C++ and other languages, this ceiling function can be safely computed using integer division to avoid floating-point inaccuracies:

\text{Row}(x) = \frac{x + m - 1}{m}

Let R_{first} = \text{Row}(s) and R_{last} = \text{Row}(s + n - 1). The total number of distinct rows Fady's group will occupy is simply:

R_{last} - R_{first} + 1

Time Complexity: per test case.

Space Complexity: .