#C2180. Splitting Array into Two Strictly Increasing Subsequences
Splitting Array into Two Strictly Increasing Subsequences
Splitting Array into Two Strictly Increasing Subsequences
You are given an array of integers \(A = [a_1, a_2, \dots, a_n]\). Your task is to determine whether it is possible to split this array into two subsequences \(B\) and \(C\) such that:
- Both \(B\) and \(C\) are strictly increasing (each element is greater than the previous one), and
- Every element in \(A\) belongs to exactly one of the two subsequences.
If such a splitting exists, print YES
followed by two lines: the first line contains the elements of the first subsequence and the second line contains the elements of the second subsequence. If there are multiple valid answers, you may print any of them. Otherwise, print NO
.
Note: A subsequence is obtained by deleting some or no elements from the array without changing the order of the remaining elements.
inputFormat
The input is given from stdin and has the following format:
- The first line contains a single integer \(t\) \((1 \le t \le 1000)\) indicating the number of test cases.
- For each test case:
- The first line contains an integer \(n\) \((2 \le n \le 2000)\), the length of the array.
- The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) \((1 \le a_i \le 10^9)\) separated by spaces.
outputFormat
For each test case, if it is possible to split the array into two strictly increasing subsequences, output YES
on a single line, then on the next line output the elements of the first subsequence separated by spaces, and on the following line output the elements of the second subsequence separated by spaces (print an empty line if a subsequence is empty).
If such a partition is not possible, output NO
on a single line.
4
5
1 3 2 4 5
4
4 3 2 1
6
1 2 3 4 5 6
3
3 1 2
YES
1 3 4 5
2
NO
YES
1 2 3 4 5 6
YES
3
1 2
</p>