#K58927. Maximum Party Guests
Maximum Party Guests
Maximum Party Guests
You are given a party with N guests. Each guest has a time interval during which they will be present at the party. Your task is to determine the maximum number of guests that are present at the party at the same time.
Formally, you are provided with an integer N and N intervals. The i-th interval is represented by two integers s_i and e_i, where s_i is the start time and e_i is the end time of the i-th guest's availability. Find the maximum number of overlapping intervals. That is, find the maximum number of guests present simultaneously.
Note: If a guest leaves at time t and another guest arrives at time t, they are not considered to be present at the party at the same time. Mathematically, each interval is considered as [s_i, e_i)
The underlying idea is to use a sweep-line algorithm where events are processed in a sorted order. The events include the start and end times of each interval. When processing an event, if it is a starting event, the guest count increases; if it is an ending event, it decreases. The maximum count recorded during this process is the answer.
inputFormat
The first line contains an integer N, the number of guests.
Each of the following N lines contains two integers s and e denoting the start and end times of a guest's stay. All input is read from standard input.
outputFormat
Output a single integer — the maximum number of guests present at the party at the same time. Write your answer to standard output.
## sample5
1 4
2 6
4 7
5 8
3 5
3
</p>