#B4274. Number Adjustment Game
Number Adjustment Game
Number Adjustment Game
You are given a list of numbers. You need to perform a series of adjustments according to the following rules:
- Step 1: Select one occurrence of the minimum number from the list and change its value to be equal to the second smallest number in the list. (In \( \LaTeX \) format: change the selected \( \min \) value \( a \) to the value \( b \), where \( b \) is the second smallest distinct number.)
- Step 2: Select one occurrence of the maximum number from the list and change its value to be equal to the second largest number in the list. (In \( \LaTeX \) format: change the selected \( \max \) value \( x \) to the value \( y \), where \( y \) is the second largest distinct number.)
- Repeat steps 1 and 2 alternately.
- If at any point the list contains fewer than three distinct numbers, stop the adjustments.
Your task is to calculate the total number of adjustments performed and report the minimum and maximum number in the final list.
Example 1:
For the list: \(2, 2, 2, 2\)
Since there is only one distinct number, no adjustment is made. The output is:
Example 2:
For the list: \(1, 3, 4, 2\)
- First adjustment: change the minimum value \(1\) to the second smallest value \(2\). The list becomes: \(2, 3, 4, 2\).
- Second adjustment: change the maximum value \(4\) to the second largest value \(3\). The list becomes: \(2, 3, 3, 2\).
Now the list contains only two distinct numbers (\(2\) and \(3\)), so the adjustments stop. The output is:
\[ \boxed{2\quad 2\quad 3} \]inputFormat
The input consists of two lines. The first line contains a single integer (n) (where (n \ge 1)) representing the number of elements. The second line contains (n) space-separated integers.
outputFormat
Output three integers separated by spaces. The first integer is the total number of adjustments performed, the second is the minimum number in the final list, and the third is the maximum number in the final list.
sample
4
2 2 2 2
0 2 2