#C1658. Longest Increasing Subarray
Longest Increasing Subarray
Longest Increasing Subarray
Given an array of integers, your task is to find the longest strictly increasing contiguous subarray.
A subarray is defined as a sequence of consecutive elements from the original array. The subarray should have the property that each element is strictly greater than its previous element.
If there are multiple subarrays satisfying the condition with the same maximum length, output the one that appears first.
You need to output the length of the longest subarray on the first line, and on the second line, output the elements of that subarray separated by a space.
Note: When no elements are present (i.e. an empty array), output 0 on a single line.
Formally, if the input array is represented as \( a_1, a_2, \ldots, a_n \), find indices \( i \) and \( j \) (with \( 1 \le i \le j \le n \)) such that \( a_i < a_{i+1} < \cdots < a_j \) and \( j-i+1 \) is maximized.
inputFormat
The input is provided via standard input (stdin) and consists of two lines:
- The first line contains an integer \( n \) representing the number of elements in the array.
- If \( n > 0 \), the second line contains \( n \) space-separated integers representing the array elements.
outputFormat
The output should be written to standard output (stdout) and consists of:
- The first line should contain the length of the longest strictly increasing contiguous subarray.
- If the length is greater than 0, the second line should contain the elements of the subarray separated by a space.
- For an empty array (\( n=0 \)), output only a single line with 0.
5
1 2 3 2 4
3
1 2 3
</p>