比赛 20160419s 评测结果 AAAAAAAAAA
题目名称 扑克游戏 最终得分 100
用户昵称 _Horizon 运行时间 0.022 s
代码语言 C++ 内存使用 0.56 MiB
提交时间 2016-04-19 08:26:39
显示代码纯文本
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define maxn 100010
using namespace std;

typedef long long ll;

int n;
int a[maxn];

priority_queue<ll, vector<ll>, greater<ll> > Q;

int main(){
	freopen("poker.in", "r", stdin);
	freopen("poker.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++)
	    scanf("%d", &a[i]), Q.push(a[i]);
	ll sum = 0;
	while(Q.size() > 1){
		ll u = Q.top(); Q.pop();
		ll v = Q.top(); Q.pop();
		ll now = u + v;
		sum += now;
		Q.push(now);
	}
	cout << sum << endl;
	return 0;
}