#C1573. Construct Balanced BST
Construct Balanced BST
Construct Balanced BST
Given (n) unique integers, your task is to determine whether it is possible to construct a balanced Binary Search Tree (BST) using these integers. A BST is considered balanced if for every node, the height difference between its left and right subtrees does not exceed 1. If possible, output an insertion order such that when the integers are inserted into an initially empty BST in that sequence, the resulting tree is balanced. The intended approach is a divide-and-conquer strategy, where the median element (after sorting) is chosen as the root, and the procedure is applied recursively on the left and right segments of the sorted list.
Note: If (n = 0), output only "NO". Otherwise, print "YES" on the first line and a valid insertion order on the second line. All input and output operations should be performed via standard input (stdin) and standard output (stdout), respectively.
inputFormat
Input is read from standard input (stdin).
The first line contains an integer (n) ((n \ge 0)), representing the number of unique integers. If (n > 0), the second line contains (n) space-separated integers.
outputFormat
Output should be written to standard output (stdout).
If (n = 0), output a single line with "NO". Otherwise, output two lines: the first line must contain "YES", and the second line must contain the space-separated integers representing one possible insertion order that constructs a balanced BST.## sample
1
5
YES
5
</p>