#K13961. Longest Non-Decreasing Subarray

    ID: 24029 Type: Default 1000ms 256MiB

Longest Non-Decreasing Subarray

Longest Non-Decreasing Subarray

You are given an array of integer temperatures. Your task is to find the longest continuous subarray in which each element is greater than or equal to the previous one. In other words, given an array \(a_1, a_2, \dots, a_N\), find the longest contiguous segment \(a_i, \dots, a_j\) such that \(a_k \le a_{k+1}\) for every \(i \le k < j\). If there are multiple segments with the same maximum length, return the first one found.

Example: For the array [3, 5, 7, 6, 9, 10, 12, 1, 2, 3], the longest non-decreasing subarray is [6, 9, 10, 12].

inputFormat

The input is given via standard input (stdin) and has the following format:

T
N
a[1] a[2] ... a[N]
N
a[1] a[2] ... a[N]
...

Where:

  • T is the number of test cases.
  • For each test case, the first line contains an integer N representing the number of temperature readings.
  • The second line contains N space-separated integers representing the temperatures.

outputFormat

For each test case, output the longest non-decreasing subarray as space-separated integers on a new line. The output is written to standard output (stdout).

## sample
1
10
3 5 7 6 9 10 12 1 2 3
6 9 10 12