题库练习 Appleman and Toastman
← 上一题 下一题 →

A9640 | Appleman and Toastman

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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?

输入格式

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.

输出格式

Print a single integer — the largest possible score.

输入输出样例

输入 #1
3
3 1 5
输出 #1
26
输入 #2
1
10
输出 #2
10
C++ 编辑器
输入
输出