#K62892. Minimum Number of Rooms
Minimum Number of Rooms
Minimum Number of Rooms
You are given a list of events, each characterized by a start time and an end time. Your task is to determine the minimum number of rooms required to schedule all the events such that no two overlapping events occur in the same room.
Formally, for a list of events represented by intervals \( [s_i, e_i] \), you must compute the value \( R \) defined as:
[ R = \max_{t}\left{\sum_{i=1}^{n} \mathbf{1}_{{s_i \le t < e_i}}\right} ]
where \( \mathbf{1}_{\{s_i \le t < e_i\}} \) is 1 if the event \( i \) is ongoing at time \( t \), and 0 otherwise. The answer is the maximum number of overlapping events at any time.
If no events are provided, output 0.
inputFormat
The first line contains a non-negative integer \( n \) representing the number of events. Each of the next \( n \) lines contains two integers separated by space, representing the start time and end time of an event.
For example:
4 1 3 2 4 3 5 7 8
outputFormat
Output a single integer which is the minimum number of rooms required to schedule all events without overlaps.
## sample4
1 3
2 4
3 5
7 8
2