Problem D
Dance
Languages
da
en
is

The line outside the city’s most popular Lindy Hop venue is longer than ever! Because security and coat checking takes significant time, the music and dancing starts as soon as the first couple hits the floor, even though most couples are still standing in line.
Although Lindy Hop is danced with a single partner, it is common to swap partners between dances. Lindy Hop involves lots of acrobatics, such as throwing and twirling, and is most fun to dance with somebody of similar height. Thus, every time a new couple checks into the venue, the guests quickly re-organise themselves into pairs of similar height. How well could the guests do if they swapped partners optimally and wanted to minimise the largest height difference of the pairs currently in the venue?
In pair dancing, participants have different roles referred
to as “leader” and “follower”. For the purpose of this task
each guest is either a leader or a follower and each couple
consist of one leader and one follower. Formally, after
over all permutations
Input
-
One line with the number
of couples. -
lines, the th of which contains the heights of the th couple’s leader and follower.
Output
For each
Sample Input 1 | Sample Output 1 |
---|---|
2 183 175 176 180 |
8 3 |
Sample Input 2 | Sample Output 2 |
---|---|
1 183 185 |
2 |