Codeforces Round 263 (Div. 1)
A
Appleman and Toastman
Codeforces
1200
原题
←B →
翻译中…

Appleman and Toastman play a game. Initially Appleman gives one group of $*n*$ numbers to the Toastman, then they start to complete the following tasks:

翻译中…
  • Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman.
  • Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
翻译中…

After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 3·10^{5}$). The second line contains $*n*$ integers $*a*_{1}$, $*a*_{2}$, ..., $*a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ 10^{6}$) — the initial group that is given to Toastman.

翻译中…

Output

翻译中…

Print a single integer — the largest possible score.

翻译中…

Note

翻译中…

Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.

翻译中…

样例

Input #1
3
3 1 5
Output #1
26
InputCopy OutputCopy
Input #2
1
10
Output #2
10
InputCopy OutputCopy
题目信息
题号
461A
时间限制
2 s
内存限制
256 MB
标签
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。