#include<iostream>
#include<string.h>
#include<string>
#include<stack>
#include<queue>
#include<functional>
#include<set>
#include<map>
#include<stdlib.h>
#include<vector>
#include<math.h>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
int main()
{
int n;
long long num = 0;
scanf("%d", &n);
priority_queue<int, vector<int>, greater<int> > pq;
for (int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
pq.push(x);
}
while (pq.size() > 1)
{
int a, b;
a = pq.top();
pq.pop();
b = pq.top();
pq.pop();
num += a + b;
pq.push(a + b);
}
printf("%lld\n", num);
return 0;
}
//注意int溢出了,要用long long
H - Fence Repair
最新推荐文章于 2018-08-08 16:07:46 发布