OracleOA #10
Minimum Difference Sum
Estimated EasyJudge-ready
Topics (AI-labelled)In-place Arrays
You may rearrange the array arbitrarily. Find the minimum sum of the absolute differences between adjacent elements; output only the cost, not the arrangement.
Input
The first line contains n, and the second line contains n integers. Full original bounds: 2≤n≤100000, 0≤a[i]≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
3
1 3 2
Output:
2
Example 2
Input:
2
5 5
Output:
0
Example 3
Input:
3
0 10 0
Output:
10
Example notes
The outputs of the three public examples are, in order: 2; 0; 10. They were verified by independent enumeration or direct simulation.
Editorial
Loading solution…