#K826. Max Guests in Special Room
Max Guests in Special Room
Max Guests in Special Room
You are given a special room that can be used by guests. Each guest has an arrival time and a departure time. A guest can use the room if their arrival time is strictly greater than the departure time of the last accepted guest. Your task is to determine the maximum number of guests that can use the room without any overlapping use.
Note: Two guests do not conflict if the arrival time of the current guest is strictly greater than the departure time of the previously selected guest. The times are provided as integers and the maximal scheduling should be computed accordingly.
The problem can be modeled as an interval scheduling optimization problem. Formally, if we denote by \( (a_i, b_i) \) the arrival and departure times of guest \( i \), you need to select a maximum subset of guests such that if \( i \) is selected after \( j \), then \( a_i > b_j \).
inputFormat
Input is read from standard input (stdin). The first line contains an integer ( n ) representing the number of guests. Each of the following ( n ) lines contains two space-separated integers representing the arrival and departure times of each guest.
outputFormat
Output the maximum number of guests that can use the special room without overlapping times. The result should be printed to the standard output (stdout).## sample
4
1 2
2 3
3 4
1 3
2
</p>