atcoder#ARC059A. [ARC059C] いっしょ
[ARC059C] いっしょ
Score : points
Problem Statement
Evi has integers . His objective is to have equal integers by transforming some of them.
He may transform each integer at most once. Transforming an integer into another integer costs him dollars. Even if , he has to pay the cost separately for transforming each of them (See Sample 2).
Find the minimum total cost to achieve his objective.
Constraints
Input
The input is given from Standard Input in the following format:
...
Output
Print the minimum total cost to achieve Evi's objective.
2
4 8
8
Transforming the both into s will cost dollars, which is the minimum.
3
1 1 3
3
Transforming the all into s will cost dollars. Note that Evi has to pay dollar separately for transforming each of the two s.
3
4 2 5
5
Leaving the as it is and transforming the and the into s will achieve the total cost of dollars, which is the minimum.
4
-100 -100 -100 -100
0
Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is .