cswork / OA打开练习工作台

OracleOA #10

Minimum Difference Sum

估计简单可在线判题

考点(AI 标注)原地数组

You may rearrange the array arbitrarily. Find the minimum sum of the absolute differences between adjacent elements; output only the cost, not the arrangement.

输入格式

The first line contains n, and the second line contains n integers. Full original bounds: 2≤n≤100000, 0≤a[i]≤10^9.

输出格式

Output a single integer, the answer.

样例 1

输入:

3
1 3 2

输出:

2

样例 2

输入:

2
5 5

输出:

0

样例 3

输入:

3
0 10 0

输出:

10

样例说明

The outputs of the three public examples are, in order: 2; 0; 10. They were verified by independent enumeration or direct simulation.