Average and median

Consider a set S = {x₁, …, x_(k)} of natural numbers (maybe with
repetitions), with odd k. The average of S is defined as
(∑_(1 ≤ i ≤ k)x_(i))/k. The median of S is defined as the element that
is in the middle of the set after we sort it. For instance, for
S = {1, 2, 2, 4, 5}, the average is (1 + 2 + 2 + 4 + 5)/5 = 14/5 = 2.8,
and the median is 2.

You are given a set of n natural numbers, with even n. Remove exactly
one element so as to maximize the absolute value of the difference
between the average and the median.

Input

Input consists of several cases, each one with an even n, followed by n
natural numbers between 0 and 10⁹. Assume 4 ≤ n ≤ 10⁵.

Output

Print the maxim possible difference between the average and the median,
with two digits after the decimal point. To do so, include these two
lines at the beginning of your main:

        cout.setf(ios::fixed);
        cout.precision(2);

The input cases do not have precision issues.

Problem information

Author: Félix Moreno

Generation: 2026-01-25T11:32:20.540Z

© Jutge.org, 2006–2026.
https://jutge.org
