#include<iostream>
#include<queue>
using namespace std;
#define maxn 10005
int main()
{
int n = 0, data = 0;
cin >> n;
//建小堆:
//上调建堆中用greater: 父大子小 父子交换 小的上去 大的下去
priority_queue<int, vector<int>, greater<int>> pq;
for (int i = 0; i < n; i++)
{
cin >> data;
pq.push(data);
}
long long money = 0;
while (!pq.empty())
{
int top1 = pq.top();
pq.pop();
if (pq.empty())
break;
int top2 = pq.top();
pq.pop();
int coin = top1 + top2;
pq.push(coin);
money += coin;
}
cout << money;
return 0;
}
7-4 修理牧场 分数 15
最新推荐文章于 2024-11-04 19:24:37 发布