#K88492. Minimum Time Span to Attend All Events
Minimum Time Span to Attend All Events
Minimum Time Span to Attend All Events
You are given several test cases. For each test case, you are given a list of events represented by intervals. Each event is described by its start time and end time.
Your task is to compute the minimum time span required to attend all the events in the list. In other words, if the events start at times \(a_i\) and end at times \(b_i\), the answer is given by:
\[ \text{Time Span} = \max(b_i) - \min(a_i) \]
Read the input from standard input and output the result for each test case on a separate line.
inputFormat
The input begins with an integer \(T\) denoting the number of test cases. For each test case, the first line contains an integer \(N\) indicating the number of events. This is followed by \(N\) lines, each containing two integers \(a\) and \(b\) representing the start time and end time of an event.
Example:
2 3 1 3 2 5 4 8 2 6 8 5 7
outputFormat
For each test case, output a single integer on a new line denoting the minimum time span required to attend all events.
Example Output:
7 3## sample
2
3
1 3
2 5
4 8
2
6 8
5 7
7
3
</p>