8648: Arithmetic Subsequence

内存限制:128 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:0

题目描述

Given an integer array A=[a1,a2,,an] of length nn, you need to determine if there exists an integer array B=[b_1,b_2,\dots,b_n]B=[b1,b2,,bn] such that the followings hold:

  1. The array B is a rearrangement of A, i.e., there exists a permutation p=[p1,p2,,pn] of size nn such that bi=api for each 1in.
  2. The array B doesn't contain any arithmetic subsequence of length at least 33.

A sequence C=[c1,c2,,ck] is called an arithmetic subsequence of BB if and only if the followings are satisfied:

  1. There exists a sequence of indices 1i1<i2<<ikN, such that cj=bij for each 1jk;
  2. C forms an arithmetic progression, i.e., for each 1ik2, we have ci+2ci+1=ci+1ci.

输入格式

The first line contains an integer T 1T25), denoting the number of test cases.

For each test case, the first line contains an integer n(1n5000), denoting the size of the array AA.

The next line contains nn integers a1,a2,,an(1ai109), denoting the elements of the array AA.

输出格式

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.

输入样例 复制

2
4
3 6 8 9
5
1 1 1 1 1

输出样例 复制

YES
8 6 9 3 
NO