3342:【例59.1】 合并果子
#include
using namespace std;
int main() {
int n;
cin >> n;
priority_queue
for (int i=0;i
int weight;
cin >> weight;
minHeap.push(weight);
}
int totalCost = 0;
while (minHeap.size()>1) {
int first = minHeap.top();
minHeap.pop();
int second = minHeap.top();
minHeap.pop();
int cost = first + second;
totalCost += cost;
minHeap.push(cost);
}
cout << totalCost << endl;
return 0;
}











