#K49342. Longest Contiguous Non-Decreasing Subsequence on Even Indices

    ID: 28621 Type: Default 1000ms 256MiB

Longest Contiguous Non-Decreasing Subsequence on Even Indices

Longest Contiguous Non-Decreasing Subsequence on Even Indices

You are given an array of integers. Your task is to extract the elements at even indices (0-indexed) and then determine the length of the longest contiguous subsequence that is non-decreasing.

More formally, if the array is \(A = [a_0, a_1, a_2, \dots, a_{N-1}]\), consider the subsequence \(B = [a_0, a_2, a_4, \dots]\). Find the maximum length \(L\) such that there exists a contiguous segment \(B_i, B_{i+1}, \dots, B_{i+L-1}\) satisfying \(B_j \leq B_{j+1}\) for all valid \(j\).

Note: The indices are based on 0-indexing. For example, if the input array is [1, 3, 2, 4, 3], the even-indexed elements are [1, 2, 3] and the longest contiguous non-decreasing segment is the entire sequence with length 3.

inputFormat

The input begins with an integer \(T\) representing the number of test cases. For each test case, the first line contains an integer \(N\) denoting the number of elements in the sequence, and the next line contains \(N\) space-separated integers.

outputFormat

For each test case, print a single line containing the length of the longest contiguous non-decreasing subsequence found among the even-indexed elements of the sequence.

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

2 2

</p>