302393: CF461A. Appleman and Toastman

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

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$),表示一开始土司人得到的一组数。 ### 输出格式 输出一个整数,表示可能的最大的分。

题目描述

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

说明

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

题意翻译

### 问题描述 苹果人和土司人正在玩游戏。一开始苹果人把包含 $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$),表示一开始土司人得到的一组数。 ### 输出格式 输出一个整数,表示可能的最大的分。

加入题单

算法标签: