#K92167. Maximum Simultaneous Guests

    ID: 38138 Type: Default 1000ms 256MiB

Maximum Simultaneous Guests

Maximum Simultaneous Guests

You are given several test cases. In each test case, there are n guests, and each guest is available during a certain time interval. Your task is to determine the maximum number of guests that are present at the same time.

The input for each test case begins with an integer n representing the number of guests, followed by n lines; each line contains two integers a and b representing the start and end times (inclusive) of the guest's availability.

You can calculate the number of guests present at any time by considering the events when a guest arrives and when a guest leaves. Mathematically, if you define an event time as:

\(event = (time, change)\),

where \(change = +1\) for the arrival at time \(a\) and \(change = -1\) for the departure after time \(b\) (i.e. at time \(b+1\)), then sorting the events by time and computing the cumulative sum gives you the number of guests at each moment. The maximum of these sums is the answer.

Input Format: The input starts with an integer T denoting the number of test cases. For each test case, the first line contains an integer n, the number of guests. This is followed by n lines, each containing two integers a and b — the start and end times of a guest.

Output Format: For each test case, output a single integer on a new line indicating the maximum number of guests present at the same time.

Example: For a test case where the input is:

1
3
1 5
2 6
4 8

The output should be:

3

inputFormat

The first line of the input contains an integer T, the number of test cases. Each test case starts with an integer n (the number of guests), followed by n lines. Each of these lines contains two space-separated integers a and b (\(1 \leq a \leq b\)), representing the start and end times of the guest's attendance.

outputFormat

For each test case, print a single integer representing the maximum number of guests present at the same time, on a new line.

## sample
1
3
1 5
2 6
4 8
3

</p>