#K14471. Maximum Consecutive Bloom Days

    ID: 24142 Type: Default 1000ms 256MiB

Maximum Consecutive Bloom Days

Maximum Consecutive Bloom Days

Maya loves her garden, and each flower in it blooms for a specific period. Given several blooming intervals, your task is to determine the maximum number of consecutive days during which there is at least one flower in bloom.

For each test case, you are given a set of intervals \( [s,e] \) where \( s \) is the starting day and \( e \) is the ending day (inclusive). The length of an interval is given by \( e - s + 1 \). Note that the intervals may not overlap; in such cases, consider each interval separately and output the maximum length among them. In cases where intervals overlap or touch each other, they merge into a single continuous blooming period.

Your goal is to compute, for each test case, the length of the longest contiguous segment of days on which at least one flower is blooming.

inputFormat

The first line of input contains an integer \( T \) denoting the number of test cases. For each test case:

  1. The first line contains an integer \( N \), the number of blooming intervals.
  2. Each of the next \( N \) lines contains two space-separated integers \( s \) and \( e \) (with \( 1 \leq s \leq e \leq 365 \)) representing the starting and ending day of a flower's blooming period.

outputFormat

For each test case, output a single line containing the maximum number of consecutive days during which at least one flower is in bloom.

## sample
2
3
1 5
10 15
20 25
2
50 100
30 60
6

71

</p>