#K59612. Balanced Skill Pairing

    ID: 30904 Type: Default 1000ms 256MiB

Balanced Skill Pairing

Balanced Skill Pairing

You are given an even number of participants, each with an associated skill level. Your task is to form pairs of participants such that the sum of the skill levels in each pair is as balanced as possible. In other words, by pairing the smallest skill value with the largest, the second smallest with the second largest, and so on, you minimize the difference between the sums of the pairs.

Mathematically, if we denote the sorted skill levels as \(a_1 \le a_2 \le \cdots \le a_n\), then the output should be pairs \((a_1, a_n)\), \((a_2, a_{n-1})\), \(\ldots\). The problem is expressed in \(\LaTeX\) format by the formula: \(\text{Pair } a_i \text{ with } a_{n+1-i}\) for \(i = 1,2,\dots, n/2\).

inputFormat

The input is given in two parts provided via standard input (STDIN):

  1. The first line contains a single integer \(n\) representing the total number of participants (\(n\) is even).
  2. The second line contains \(n\) space-separated integers, each representing the skill level of a participant.

outputFormat

The output should be printed to standard output (STDOUT) with each line representing a pair of participants. For each pair, output the two skill levels separated by a single space. Pairs must be printed in the order determined by pairing the smallest available skill with the largest, the next smallest with the next largest, and so on.

## sample
4
1 4 3 2
1 4

2 3

</p>