#P2301. Minimizing the Conflict Index
Minimizing the Conflict Index
Minimizing the Conflict Index
In this problem, each participant selects two wooden sticks as their weapons – one for long‐distance throwing and one for close combat. However, not everyone can get the two best ones. In order to reduce disputes, Cony defined the conflict index for a person as the discomfort index, computed as \((L_1 - L_2)^2\), where \(L_1\) and \(L_2\) are the lengths of the two chosen sticks. Given that there are an even number of sticks available, your task is to pair all the sticks so that the total conflict index (the sum of \((L_1 - L_2)^2\) over all pairs) is minimized.
Hint: After sorting the sticks, an optimal strategy is to pair adjacent sticks.
inputFormat
The input begins with a single even integer N (2 ≤ N ≤ 105), representing the total number of wooden sticks. The next line contains N space-separated integers, each denoting the length of a stick. It is guaranteed that N is even.
outputFormat
Output a single integer, the minimum possible conflict index, where the conflict index for a pair with stick lengths L1 and L2 is given by \((L_1 - L_2)^2\).
sample
4
1 3 4 6
8
</p>