#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int M = 20000 + 10;
long long ans;
int n;
struct T
{
int x;
const bool operator<(T a) const
{
return a.x < x;
}
};
T heap[M];
int main()
{
priority_queue <T>que;
while(scanf("%d", &n) != EOF)
{
ans = 0;
for(int i = 1; i <= n; i++)
{
scanf("%d", &heap[i].x);
que.push(heap[i]);
}
for(int i = 1; i < n; i++)
{
T a = que.top();
que.pop();
T b = que.top();
que.pop();
ans += a.x + b.x;
a.x += b.x;
que.push(a);
}
cout<<ans<<endl;
while(que.empty())
que.pop();
}
return 0;
}
poj3253 优先队列
最新推荐文章于 2019-07-06 22:50:50 发布