CF461A Appleman and Toastman
题目描述
### 问题描述
苹果人和土司人正在玩游戏。一开始苹果人把包含 $n$ 个数的一组数给土司人,然后他们开始进行下面两个步骤:
- 每次土司人得到一组数,他把这些数的和加入到得分中,然后他把这组数交给苹果人。
- 每次苹果人得到只包含一个数的一组数,他会把这组数扔掉;每次苹果人得到包含至少两个数的一组数,他会任意的把它分成两个非空的组,并把这两组数分别交给土司人。
在这两个逗逼完成了所有的任务后他们会查看他们的分数。他们的最多能得多少分呢?
输入格式
第一行包含一个整数 $n$($1\le n\le 3\times 10^5$)。
第二行包含 $n$ 个整数 $a_1,a_2,\cdots,a_n$($1\le a_i\le 10^6$),表示一开始土司人得到的一组数。
输出格式
输出一个整数,表示可能的最大的分。
说明/提示
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.