Old cassette player (2)
P52998

Statement

html

Consider an old cassette player,
whose only working buttons are “play” and “rewind”.
You have just one cassette, which you always keep completely rewinded.
So, when you want to listen to a particular song s,
you have to press the “play” button
and wait until all the songs stored before s finish.
Afterwards, when s ends,
you always rewind the cassette.

You have n songs, which you listen to with the same frequency.
You know the duration di of every song i.
Assume that the cassette is long enough to store all your songs.
Your goal is to choose the order to store the songs
so as to minimize the expected time to listen to a desired song.

Input

Input is all natural numbers, and consists of several cases.
Every case begins with n,
which is followed by the durations of the n songs,
all strictly positive.
Assume 1 ≤ n ≤ 105.

Output

For every case,
print with four digits after the decimal point
the optimal expected time to listen to a desired song.
The input cases have no precision issues.

About statements

The official statement of a problem is always the one
in the PDF document. The HTML and PNG versions of the statement
are also given to help you, but they may contain some content
that is not well displayed. In case of doubt, always use the PDF.