Marriage agency

A marriage agency has n customers of both sex. It is known the age of
all the customers (expressed with the same unit for everybody, and it
does not have to be years; it could be months, days, etc). The two
people in charge of the agency have different opinions about how the
customers should be paired off. One of them thinks that the sum of the
differences of ages of each formed pair should be minimized. The other
one thinks just the opposite think, that is, that the sum of the
differences should be maximized.

Write a program that computes the minimal possible sum of differences
and the maximal possible sum of differences. For instance, if n = 2, the
men are 25 and 40, and the women are 20 and 50, then there only are two
possibilities: 25–20, 40–50 (with total sum 15) and 40–20, 25–50 (with
total sum 45).

Input

The input consists of 1 ≤ n ≤ 10⁴, followed by n numbers in a line with
the ages of the men, followed by n numbers in other line with the ages
of the women.

Output

Your program must print a line with two numbers separated by a space:
the minimal possible sum of the differences of ages, and the maximal
possible sum of the differences of ages. Both numbers will be between 1
and 10⁹.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:03:27.498Z

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