Permutation
시간 제한5초메모리 제한256 MB
1부터 n까지의 순열을 증가 부분수열과 감소 부분수열로 나눌 수 있는지 판정하고, 가능하면 그중 하나를 출력한다.
문제
Byteasar urgently needs two integer sequences for his research: an increasing one and a decreasing one. However, the only thing he has is a permutation of the numbers in the range . Can you help him partition this permutation into two such sequences?
Formally, we're looking for two subsequences and () such that:
- and ,
- and ,
- for all (, ),
- .
입력
The first line of the input contains a single integer () -- the number of testcases in the input file. The following lines describe the consecutive testcases.
A single testcase description consists of two lines. The first of them contains an integer () -- the length of the permutation . The following line contains integers ( and for all ) -- the permutation itself.
출력
For each testcase (in the order they appear in the input) you should output YES if the permutation can be partitioned into suitable subsequences or NO otherwise. If the partitioning is possible, you should output another two lines describing a sample solution. You should follow the format described below: In case there are many solutions, you can output any of them.