#C5131. Least Time in Office

    ID: 48747 Type: Default 1000ms 256MiB

Least Time in Office

Least Time in Office

You are given records of employees' entry and exit times over a month. Each record contains an employee ID, an entry time and an exit time, all in a 24-hour format (HHMM). The first line of the input contains three integers: n (the number of employees), d (the number of working days in the month), and r (the number of records).

Each of the following r lines represents a record in the following format:

employee_id entry_time exit_time

Your task is to calculate the total time (in minutes) each employee spent in the office during the month and determine the employee(s) who spent the least time. In case of ties, output all such employee IDs in lexicographical order.

Note: The input is read from stdin and the output should be written to stdout.

The time difference is calculated as follows: if an employee enters at time \(T_{entry}\) and exits at \(T_{exit}\), then the time spent is \(T_{exit} - T_{entry}\) (in minutes). For example, if an employee enters at 0900 and leaves at 1700, they spend \(\mathrm{480}\) minutes in the office.

inputFormat

The input is given via stdin and has the following format:

n d r
record_1
record_2
...
record_r

Where:

  • n is the number of employees.
  • d is the number of days in the month.
  • r is the total number of records.
  • Each record is a line containing an employee ID (a string without spaces), an entry time and an exit time (both in HHMM 24-hour format) separated by spaces.

outputFormat

Output a single line to stdout containing the ID(s) of the employee(s) who spent the least total time in the office. In case of multiple employees with the same minimum time, output their IDs in lexicographical order, separated by a single space.

## sample
3 4 12
emp1 0900 1700
emp2 1000 1500
emp3 1030 1800
emp1 0900 1700
emp2 1000 1500
emp3 1030 1800
emp1 0900 1700
emp2 1000 1500
emp3 1030 1800
emp1 0900 1700
emp2 1000 1500
emp3 1030 1700
emp2