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 ...
随机推荐
- java 解析 XML实例
package com.hseact.fecp.servlet; import java.io.IOException; import javax.xml.parsers.DocumentBuilde ...
- js常用的事件对象
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event. ...
- kettle根据参数动态派生列
抽取数据的时候没有日期字段,需要根据抽取日期自动生成月份,如下图结构 表输入_参数部分,接收来自其他系统传过来的参数(JAVA程序或者页面),具体设置如图 在查询数据时候派生列 运行模型的时候,给参数 ...
- elasticSearch nested exist与missing查询
elasticSearch nested查询,简单意义上,你可以理解为,它不会被索引,只是被暂时隐藏起来,而查询的时候,开关就是使用nested query/filter去查询 下面我有一个例子,是查 ...
- DispatcherTimer
1.IsEnabled 表示计时器是否已经启动. 2.DispatcherTimer处于当前线程的管理,不会新建一个线程专门用于计时操作,也就是说,当前线程可能会阻塞计时器.因此,Dispatcher ...
- C#类似版本号有多个分割符可以产生的排列组合,类似版本号比较
我采用asp.net进行演示 送给有缘人吧,可以获得类似版本号的功能,也可以对比两个版本号,我这里是其他需要用逗号分割的 using System; public partial class _Def ...
- 使用sigc++插槽系统
http://www.cppblog.com/gaimor/archive/2010/02/22/108236.html?opt=admin 我所知的c++插槽系统由3个boost的,sigslot的 ...
- Jmeter相关
关于Jmeter,这里有一篇文章可以看看:http://www.cnblogs.com/TankXiao/p/4045439.html 给有需要的同学.
- C++生成十字绣图案(二) 面向对象
基本的十字绣线性生成中提供了判断下一步可以画的位置并且逐步生成的函数.以这些基本函数为基础,可以进行更多变化的图案设计. 为了方便的扩展,可以把线性生成写成一个类,以后的修改继承这个类. 头文件Bas ...
- mac 终端 使用 gnu coreutils 工具 ls 颜色显示
mac 终端默认 ls 命令无颜色显示: 1: 使用 ls -G 可以显示基本颜色 2:使用 gnu coreutils 工具 mac 终端 使用 gnu coreutils 工具 ls 颜色显示 以 ...