#K12351. Minimum Tables Requirement

    ID: 23671 Type: Default 1000ms 256MiB

Minimum Tables Requirement

Minimum Tables Requirement

Given three integers \(N\), \(M\), and \(A\), representing the number of available tables, the maximum seating capacity of each table, and the total number of attendees respectively, determine the minimum number of tables required to seat all attendees. Each used table must either be completely filled with \(M\) attendees or have exactly \(M-1\) attendees.

The solution can be derived using the following approach:

  • Let \(t = \lfloor \frac{A}{M} \rfloor\) be the number of completely filled tables.
  • Let \(r = A \bmod M\) be the remainder (the number of attendees that do not fill a table completely).

If \(r = 0\), then the answer is \(t\). If \(r = M-1\), then an extra table that is one seat short is acceptable, so the answer is \(t+1\). Otherwise, the answer is \(\lceil \frac{A}{M} \rceil\). Note that if any of the inputs \(N\), \(M\), or \(A\) are non-positive, the answer should be 0.

inputFormat

The input consists of multiple test cases. Each test case is described in two lines:

  • The first line contains two space-separated integers \(N\) and \(M\) (number of available tables and maximum capacity per table respectively).
  • The second line contains a single integer \(A\), the total number of attendees.

The input terminates with a line containing a single "0".

outputFormat

For each test case, output a single line containing the minimum number of tables required to seat all attendees under the given conditions.

## sample
5 4
10
0
3

</p>