#C14795. Meeting Room Allocation

    ID: 44483 Type: Default 1000ms 256MiB

Meeting Room Allocation

Meeting Room Allocation

You are given a set of meetings. Each meeting is defined by three integers: meeting_id, start_time, and end_time. The start_time must be strictly less than the end_time. Your task is to allocate meeting rooms for these meetings such that the total number of rooms used is minimized. If two meetings do not overlap, they can use the same room.

Note: If any meeting has an invalid time interval (i.e. start_timeend_time), your program should output an error message in the format:

\(\text{Error: Invalid meeting times: start\_time (X) should be less than end\_time (Y).}\)

Example 1: For input 3\n1 10 20\n2 21 30\n3 31 40\n, the meetings do not overlap, so only one room is needed. The output will be:

1
1 1
2 1
3 1

Example 2: For input 3\n1 10 20\n2 15 25\n3 20 30\n, meeting 1 and meeting 3 can share the same room, but meeting 2 overlaps with meeting 1. Thus, two rooms are needed. The output will be:

2
1 1
2 2
3 1

inputFormat

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

  • The first line contains a single integer n, representing the number of meetings.
  • The next n lines each contain three space‐separated integers: meeting_id, start_time, and end_time.

It is guaranteed that the meeting_ids are unique.

outputFormat

If all meetings have valid times, the output is printed to standard output (stdout) in the following format:

  • The first line contains the minimum number of meeting rooms used.
  • The next n lines each contain two integers separated by a space: the first is the meeting_id and the second is the allocated room number. The meetings should be listed in increasing order of meeting_id.

If any meeting is invalid, output the error message and terminate. The error message format is:

Error: Invalid meeting times: start_time (X) should be less than end_time (Y).

## sample
0
0

</p>