#K12866. Student Arrangement Problem
Student Arrangement Problem
Student Arrangement Problem
You are given the heights of N students. Your task is to determine if it is possible to arrange them in a line such that no student is positioned exactly between two students of the same height.
Note: In this problem, an arrangement is considered possible if and only if all the students have distinct heights. If there is any duplicate height, you should output that no valid arrangement exists.
If an arrangement is possible, you must output "YES" followed by one valid arrangement (which is simply the students' heights in increasing order). Otherwise, output "NO".
The condition essentially reduces to verifying that there are no duplicate heights. Formally, given a sorted list of heights \(h_1, h_2, \ldots, h_N\), the arrangement is valid if \(h_i \neq h_{i-1}\) for every \(2 \le i \le N\). Otherwise, no valid arrangement exists.
inputFormat
The input is read from stdin and has the following format:
T N h1 h2 ... hN N h1 h2 ... hN ...
Where:
- T is the number of test cases.
- For each test case, the first line contains an integer N, representing the number of students.
- The next line contains N space-separated integers denoting the heights of the students.
outputFormat
For each test case, if an arrangement is possible (i.e. all heights are distinct), output YES
on one line followed by a line containing the arranged heights in increasing order (space separated). Otherwise, output NO
on a single line.
The output should be printed to stdout.
## sample1
3
1 2 2
NO
</p>