CodeForces 461A Appleman and Toastman
来源:互联网 发布:主流erp软件 编辑:程序博客网 时间:2024/06/04 18:31
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·105). The second line containsn integersa1,a2, ...,an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
33 1 5
26
110
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.
#include<cstring>#include<iostream>#include<algorithm>#define K 300010using namespace std;int number[K];int main(){ int n,k,i; long long sum,group; while(cin>>n){ sum=0; k=0; for(i=0;i<n;i++){ cin>>number[i]; sum+=number[i]; } group=sum; int x=n-1; sort(number,number+n); while(k!=x){ sum+=number[k]; group-=number[k]; sum+=group; k++; } cout<<sum<<endl; } return 0;}
- Codeforces-461A Appleman and Toastman
- Appleman and Toastman - CodeForces 461 A 水题
- Codeforces 461A Appleman and Toastman
- Codeforces 461A Appleman and Toastman(贪心)
- codeforces 461A Appleman and Toastman
- 【codeforces】 461A Appleman and Toastman
- CodeForces 461A Appleman and Toastman(贪心)
- CodeForces 461A Appleman and Toastman
- CodeForces 461A Appleman and Toastman
- codeforces 461A Appleman and Toastman
- 461A - Appleman and Toastman
- A. Appleman and Toastman(codeforces#263div1)
- A. Appleman and Toastman
- CF 461 A Appleman and Toastman
- 【CODEFORCES】 C. Appleman and Toastman
- Codeforces Round #263 (Div. 1) A. Appleman and Toastman
- CodeForces-462C Appleman and Toastman
- CodeForces 462C Appleman and Toastman 贪心
- Swift版MD5加密
- 用java模拟dos树结构(tree命令)第二弹
- TQ2440裸机实验(复制nand flash 前4K到SDRAM)
- ffmep
- Note: An exception occurred while getting the Javadoc. (file not on classpath)
- CodeForces 461A Appleman and Toastman
- 2016年开篇
- 在sublime中写注释的规范
- ios 单独集成qq和微信分享sdk的方法
- 修改 app 在真机或虚拟机上的名称
- 用python编写daemon监控进程并自动恢复
- 输入框一些校验的小技巧合计
- Sicily 4700. 小明与奶牛
- python MySQLdb问题