#C6445. Rainfall Pattern Analysis

    ID: 50206 Type: Default 1000ms 256MiB

Rainfall Pattern Analysis

Rainfall Pattern Analysis

You are given several test cases describing rainfall measurements over a period of time. For each test case, you are provided an integer N and a sequence of N integers representing the rainfall values. Your task is to determine the length of the longest subsequence which first forms a strictly increasing sequence and then forms a strictly decreasing sequence. Both the increasing part and the decreasing part must have length at least 2. If no such pattern exists, output 0.

Formally, for an array \(a_1, a_2, \dots, a_N\), you must find an index \(i\) such that \(a_{j} < a_{j+1}\) for \(1 \leq j < i\) and \(a_{j} > a_{j+1}\) for \(i \leq j < N\) with \(i > 1\) and \(N-i+1 > 1\), and maximize the value \(\text{inc}[i] + \text{dec}[i] - 1\), where \(\text{inc}[i]\) is the length of the increasing run ending at index \(i\) and \(\text{dec}[i]\) is the length of the decreasing run starting at index \(i\).

inputFormat

The first line contains an integer T representing the number of test cases. For each test case, the first line contains an integer N denoting the number of rainfall measurements. The second line contains N space-separated integers representing the rainfall values.

outputFormat

For each test case, output a single integer on a new line representing the length of the longest subsequence that forms a strictly increasing sequence followed by a strictly decreasing sequence. If no such pattern exists, output 0.

## sample
1
10
1 2 3 4 5 4 3 2 1 0
10

</p>