#K36292. Maximum Overlapping Friends

    ID: 25722 Type: Default 1000ms 256MiB

Maximum Overlapping Friends

Maximum Overlapping Friends

You are organizing a party and have invited several friends. Each friend arrives and departs at specific times. Your task is to determine the maximum number of friends that are present at the party at the same time.

Given n intervals, where each interval is represented by two integers indicating the arrival and departure times, compute the maximum number of overlapping intervals. This is equivalent to finding the maximum number of friends present simultaneously.

Note: If a friend departs at the same time another friend arrives, the departure is considered to occur before the arrival.

The formula to compute the maximum overlap is based on the sweep line algorithm. In mathematical terms, if we denote events as \(e_i = (t_i, \delta_i)\) where \(\delta_i = +1\) for an arrival and \(\delta_i = -1\) for a departure, then the maximum number of overlapping intervals is:

[ \max_{i} \left( \sum_{j=1}^{i} \delta_j \right) ]

inputFormat

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

  • The first line contains a single integer n (1 ≤ n ≤ 105), the number of friends (or intervals).
  • The next n lines each contain two space-separated integers representing the arrival time and departure time for each friend.

outputFormat

Output a single integer to standard output (stdout): the maximum number of friends that are present at the party simultaneously.

## sample
3
1 4
2 5
6 8
2

</p>