

Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 点
問題文
個の整数 が与えられます。えび君はこれらを書き換えて全て同じ整数にしようとしています。各は高々一回しか書き換えられません(書き換えなくても良い)。整数を整数に書き換えるとき、コストがかかります。仮にだとしても、ひとつ分のコストで同時に書き換えることは出来ません(入出力例 を参照)。えび君が目的を達成するのに必要なコストの総和の最小値を求めてください。
制約
入力
入力は以下の形式で標準入力から与えられる。
...
出力
えび君が全てを同じ整数に書き換えるのに必要なコストの総和の最小値を出力せよ。
入力例 1Copy
2 4 8
出力例 1Copy
8
全てをに書き換えると、コストの総和はとなり、これが最小です。
入力例 2Copy
3 1 1 3
出力例 2Copy
3
全てをに書き換えるととなります。各ごとに書き換えるので、二つのを一度にコストで書き換えられるわけではないことに注意してください。
入力例 3Copy
3 4 2 5
出力例 3Copy
5
は書き換えずに、とを共にに書き換えることでが達成できて、これが最小です。
入力例 4Copy
4 -100 -100 -100 -100
出力例 4Copy
0
何も書き換えなくともえび君は目的を達成しています。よってこの場合コストはです。
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.
Sample Input 1Copy
2 4 8
Sample Output 1Copy
8
Transforming the both into s will cost dollars, which is the minimum.
Sample Input 2Copy
3 1 1 3
Sample Output 2Copy
3
Transforming the all into s will cost dollars. Note that Evi has to pay dollar separately for transforming each of the two s.
Sample Input 3Copy
3 4 2 5
Sample Output 3Copy
5
Leaving the as it is and transforming the and the into s will achieve the total cost of dollars, which is the minimum.
Sample Input 4Copy
4 -100 -100 -100 -100
Sample Output 4Copy
0
Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is .