#P8236. Expected Score of Random Stone Merging
Expected Score of Random Stone Merging
Expected Score of Random Stone Merging
You are given n piles of stones, where the i-th pile contains ai stones. You will perform n-1 operations. In each operation, you randomly choose two piles and merge them into a single pile. The score obtained in this operation is equal to the sum of the sizes of the two chosen piles.
After performing all merge operations, you will end up with one pile. Your task is to calculate the expected total score if at every merge you choose two piles uniformly at random.
Let \(S = \sum_{i=1}^{n}a_i\) be the total number of stones, and \(H_n = \sum_{i=1}^{n}\frac{1}{i}\) be the \(n\)th harmonic number. It can be shown that the expected score is:
\[ \text{Expected Score} = 2S\left(H_{n}-1\right). \]inputFormat
The first line contains an integer n
(n \(\geq\) 2) representing the number of piles.
The second line contains n
integers \(a_1, a_2, \dots, a_n\) representing the number of stones in each pile.
outputFormat
Output the expected total score. Print the answer as a floating-point number with at least 6 digits of precision.
sample
2
3 5
8.000000