Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has brought a box of packets of candies and would like to distribute one packet to each of the children. Each of the packets contains a number of candies. He wants to minimize the cumulative difference in the number of candies in the packets he hands out. This is called the unfairness sum. Determine the minimum unfairness sum achievable.
For example, he brings packets where the number of candies is . There are children. The minimum difference between all packets can be had with from indices and . We must get the difference in the following pairs: . We calculate the unfairness sum as: