|
||||||||||
Arithmetic SubsequenceTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 959 Accepted Submission(s): 405 Special Judge Problem Description Given an integer array $A=[a_1,a_2,\dots,a_n]$ of length $n$, you need to determine if there exists an integer array $B=[b_1,b_2,\dots,b_n]$ such that the followings hold: <ol> <li> The array $B$ is a rearrangement of $A$, i.e., there exists a <strong>permutation</strong> $p=[p_1,p_2,\dots,p_n]$ of size $n$ such that $b_i=a_{p_i}$ for each $1\leq i\leq n$. </li> <li> The array $B$ doesn't contain any <strong>arithmetic subsequence</strong> of length at least $3$. </li> </ol> A sequence $C=[c_1,c_2,\dots,c_k]$ is called an <strong>arithmetic subsequence</strong> of $B$ if and only if the followings are satisfied: <ol> <li> There exists a sequence of indices $1\leq i_1\lt i_2\lt\dots\lt i_k\leq N$, such that $c_j=b_{i_j}$ for each $1\leq j\leq k$; </li> <li> $C$ forms an arithmetic progression, i.e., for each $1 \leq i\leq k-2$, we have $c_{i+2}-c_{i+1}=c_{i+1}-c_{i}$. </li> </ol> Input The first line contains an integer $T$ ($1 \le T \le 25$), denoting the number of test cases. For each test case, the first line contains an integer $n(1\leq n\leq 5000)$, denoting the size of the array $A$. The next line contains $n$ integers $a_1,a_2,\dots,a_n(1\leq a_i\leq 10^9)$, denoting the elements of the array $A$. Output For each test case, if no such array $B$ exists, output ''NO''(without quotes) in a line. Otherwise, output ''YES''(without quotes) in a line, and in the next line output a valid array $B$. If there are multiple arrays $B$ that satisfy the requirement, outputting any of them would be considered correct. Sample Input
Sample Output
Source | ||||||||||
|