比赛 板子大赛 评测结果 WWWWWWWWWW
题目名称 石子合并 最终得分 0
用户昵称 Asher 运行时间 0.029 s
代码语言 C++ 内存使用 3.30 MiB
提交时间 2025-01-22 12:36:58
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
long long n, a, l, ans; 
priority_queue<int> pq;
int main()
{
	freopen("shizi.in", "r", stdin);
	freopen("shizi.out", "w", stdout);
	cin >> n;
	for(int i = 1;i <= n; i++)
	{
		cin >> a;
		pq.push(-a);
	}
	while(1)
	{
		ans += l;
		l = pq.top();
		pq.pop();
		if(pq.empty())
			break;
		l += pq.top();
		pq.pop();
		pq.push(l);
	}
	cout << -ans;
    return 0;
}