GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday 25 May 2022

[Solution] Circular Local MiniMax Codeforces Solution | Codeforces Problem Solution 2022

C. Circular Local MiniMax
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

  • bi1<bi>bi+1
  • bi1>bi<bi+1

To make sense of the previous formulas for i=1 and i=n

Solution Click Below:-  CLICK HERE

one shall define b0=bn and bn+1=b1.

Input

The first line of the input contains a single integer t (1t3104)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (3n105)  — the number of integers.

The second line of each test case contains n integers a1,a2,,an (0ai109).

The sum of n over all test cases doesn't exceed 2105.

Output

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.

No comments:

Post a Comment