#C5654. Split Array into Three Increasing Subarrays
Split Array into Three Increasing Subarrays
Split Array into Three Increasing Subarrays
Given a sequence of distinct integers, determine whether the sequence can be partitioned into three contiguous subarrays such that each subarray is strictly increasing. A sequence [a1, a2, ..., ak] is strictly increasing if:
\( a_1 < a_2 < \cdots < a_k \)
The partition is valid if there exist two indices \(i\) and \(j\) with \(1 \le i < j \le n-2\) such that the element at each of these positions forms a "peak" (i.e. an element that is greater than its immediate neighbors). More formally, a peak at position \(k\) satisfies:
\( a_{k-1} a_{k+1} \)
Output YES
if such a partition exists, and NO
otherwise.
inputFormat
The first line of input contains an integer T
representing the number of test cases. Each test case is described as follows:
- The first integer is
n
— the number of elements in the sequence. - This is followed by
n
space-separated integers representing the sequence.
All input is given via standard input.
outputFormat
For each test case, output a single line with either YES
if the sequence can be partitioned into three contiguous strictly increasing subarrays according to the rules described, or NO
otherwise. Output should be printed to standard output.
4
5 1 2 3 4 5
7 1 3 2 5 6 7 4
4 1 3 2 4
9 1 2 1 3 4 2 5 6 7
NO
YES
NO
YES
</p>