#C1999. Maximizing Session Participants

    ID: 45265 Type: Default 1000ms 256MiB

Maximizing Session Participants

Maximizing Session Participants

In this problem, you are given a total number of participants and a set of preferences specifying each participant's desired time slot. Each session can accommodate at most ( k ) participants. For each unique time slot, if there are ( c ) participants, the number of sessions needed is ( \lceil \frac{c}{k} \rceil ) and the maximum number of participants that can be accommodated in that slot is ( \min(c, k \cdot \lceil \frac{c}{k} \rceil) ). Your task is to compute the maximum total number of participants that can be scheduled across all time slots. Note that each participant attends only one session and only those participants who stated a preference can be scheduled.

The input begins with three integers ( n ), ( k ), and ( m ) where:

  • ( n ) is the total number of participants,
  • ( k ) is the maximum number of participants per session,
  • ( m ) is the number of participants who specified a time slot preference.

The following ( m ) lines each contain a participant identifier and an integer representing the preferred time slot. Output a single integer representing the total number of participants that can be accommodated.

inputFormat

The input is read from standard input and has the following format:

The first line contains three integers separated by spaces: ( n ) ( k ) ( m ).

The next ( m ) lines each contain a participant ID (a string without spaces) and an integer (the preferred time slot), separated by a space.

outputFormat

Output a single integer to standard output denoting the maximum number of participants that can be accommodated in the sessions.## sample

6 2 6
P1 10
P2 14
P3 10
P4 16
P5 14
P6 16
6