Codeforces Round #263 (Div. 2) proC
题目:
2 seconds
256 megabytes
standard input
standard output
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 contains n integers a1, a2,
..., an (1 ≤ ai ≤ 106)
— the initial group that is given to Toastman.
Print a single integer — the largest possible score.
3
3 1 5
26
1
10
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 <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream> using namespace std; long long a[300005];
int main()
{
int n;
long long ans;
while(scanf("%d",&n)!=EOF)
{
ans=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
{
a[i]+=a[i-1];
}
ans=a[n];
for(int i=0;i<=n-2;i++)
{
ans+=(a[n]-a[i]);
}
cout<<ans<<endl;
}
}
Codeforces Round #263 (Div. 2) proC的更多相关文章
- 贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman
题目传送门 /* 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 */ /************************************************ Author :R ...
- Codeforces Round #263 (Div. 2)
吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include &l ...
- Codeforces Round #263 (Div. 1)
B 树形dp 组合的思想. Z队长的思路. dp[i][1]表示以i为跟结点的子树向上贡献1个的方案,dp[i][0]表示以i为跟结点的子树向上贡献0个的方案. 如果当前为叶子节点,dp[i][0] ...
- Codeforces Round #263 Div.1 B Appleman and Tree --树形DP【转】
题意:给了一棵树以及每个节点的颜色,1代表黑,0代表白,求将这棵树拆成k棵树,使得每棵树恰好有一个黑色节点的方法数 解法:树形DP问题.定义: dp[u][0]表示以u为根的子树对父亲的贡献为0 dp ...
- Codeforces Round #263 (Div. 2) D. Appleman and Tree(树形DP)
题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input ...
- Codeforces Round #263 (Div. 2) A B C
题目链接 A. Appleman and Easy Task time limit per test:2 secondsmemory limit per test:256 megabytesinput ...
- Codeforces Round #263 (Div. 1) C. Appleman and a Sheet of Paper 树状数组暴力更新
C. Appleman and a Sheet of Paper Appleman has a very big sheet of paper. This sheet has a form of ...
- Codeforces Round #263 (Div. 2)C(贪心,联想到huffman算法)
数学家伯利亚在<怎样解题>里说过的解题步骤第二步就是迅速想到与该题有关的原型题.(积累的重要性!) 对于这道题,可以发现其实和huffman算法的思想很相似(可能出题人就是照着改编的).当 ...
- Codeforces Round #263 (Div. 2) proB
题目: B. Appleman and Card Game time limit per test 1 second memory limit per test 256 megabytes input ...
随机推荐
- 运用CSS改进网站设计的3个技巧
CSS是一种分离表述编码和实际内容的一种最有用的方式,也是一种使搜索引擎最优化的方式,通常,网站设计中会建立一整套的css样式标准,这些标准存储在一个扩展名为css的单独文件中.然后利用HTML标签设 ...
- Android -- ImageLoader本地缓存
传送门 <Android -- ImageLoader简析> http://www.cnblogs.com/yydcdut/p/4008097.html 本地缓存 在缓存文件时对文件名称 ...
- AngularJS是什么?
AngularJS扩展了HTML? 看了几天AngularJS的各种中文教程,一直没有理解AngularJS是做什么的. 直到今天了英文文档,才有了初步了解. HTML是静态语言. JavaScrip ...
- Hibernate框架简介(二)基本使用增、删、改、查
一.Hibernate框架简介 Hibernate是一个优秀的Java持久化层解决方案,是当今主流的对象-关系映射(ORM,ObjectRelationalMapping)工具 1.1.理解持久化 瞬 ...
- PyQt5教程——介绍(1)
PyQt5教程阅读须知 “PyQt5教程”系列若不做明显提示,默认翻译自zetcode. 有需要翻译精度的朋友可以自行阅读英文文档. 如果本系列博文侵犯了您的合法权益,请在博客中留下评论或联系:che ...
- 文本框只支持数字、小数点、退格符、负号、Del键
Public Function OnlyNumberAndDot(inKeyAscii As Integer) As Integer '函数说明:文本框只支持数字.小数点.退格符.负号.Del键 '入 ...
- Eclipse——工作台
Workspace 磁盘区域.存放工作资料
- openerp many2many
many2many (0,0,{values}) 根据values里面的信息新建一个记录. (1,ID,{values})更新id=ID的记录(写入values里面的数据) (2,ID) 删除id=I ...
- Android中onTouch与onClick事件的关系
这几天遇到点关于Android的触摸事件相关的,还跟onClick有关.暂且记下: LinearLayout分别设置了onTouchListener,onClickListener,onLongCli ...
- maven 创建web项目的标准目录结构
maven 创建web项目的标准目录结构 CreateTime--2018年4月18日21:05:37 Author:Marydon 1.标准目录介绍(开发目录) 2.在eclipse下,目录展示 ...