CF1685A.Circular Local MiniMax
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n integers a1,a2,…,an . Is it possible to arrange them on a circle so that each number is strictly greater than both its neighbors or strictly smaller than both its neighbors?
In other words, check if there exists a rearrangement b1,b2,…,bn of the integers a1,a2,…,an such that for each i from 1 to n at least one of the following conditions holds:
- bi−1<bi>bi+1
- bi−1>bi<bi+1
To make sense of the previous formulas for i=1 and i=n , one shall define b0=bn and bn+1=b1 .
输入格式
The first line of the input contains a single integer t ( 1≤t≤3⋅104 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n ( 3≤n≤105 ) — the number of integers.
The second line of each test case contains n integers a1,a2,…,an ( 0≤ai≤109 ).
The sum of n over all test cases doesn't exceed 2⋅105 .
输出格式
For each test case, if it is not possible to arrange the numbers on the circle satisfying the conditions from the statement, output NO . You can output each letter in any case.
Otherwise, output YES . In the second line, output n integers b1,b2,…,bn , which are a rearrangement of a1,a2,…,an and satisfy the conditions from the statement. If there are multiple valid ways to arrange the numbers, you can output any of them.
输入输出样例
输入#1
4 3 1 1 2 4 1 9 8 4 4 2 0 2 2 6 1 1 1 11 111 1111
输出#1
NO YES 1 8 4 9 NO YES 1 11 1 111 1 1111
说明/提示
It can be shown that there are no valid arrangements for the first and the third test cases.
In the second test case, the arrangement [1,8,4,9] works. In this arrangement, 1 and 4 are both smaller than their neighbors, and 8,9 are larger.
In the fourth test case, the arrangement [1,11,1,111,1,1111] works. In this arrangement, the three elements equal to 1 are smaller than their neighbors, while all other elements are larger than their neighbors.