#P7789. [COCI 2016/2017 #6] Sirni
[COCI 2016/2017 #6] Sirni
Description
There are cards, and each card has a value written on it.
You may connect any two cards, but the cost is .
Please find the minimum total cost to connect all cards.
Input Format
The first line contains an integer , meaning there are cards.
The next lines each contain a positive integer , representing the value written on the -th card.
Output Format
One line containing one integer, representing the minimum total cost.
4
2
6
3
11
1
4
1
2
3
4
0
3
4
9
15
4
Hint
Sample Explanation #1
Connect card and card , the cost is .
Connect card and card , the cost is .
Connect card and card , the cost is .
The total cost is .
Constraints
For of the testdata, .
For another of the testdata, .
For of the testdata, , .
Notes
The score of this problem follows the original COCI settings, with a full score of .
Translated from COCI2016_2017 CONTEST #6 T5 SIRNI.
Translated by ChatGPT 5
京公网安备 11011102002149号