提交时间:2024-08-19 22:01:52
运行 ID: 168044
#include <iostream> #include <vector> #include <queue> using namespace std; int main() { int n; cin >> n; priority_queue<int, vector<int>, greater<int>> minHeap; vector<int> laziness(n); for (int i = 0; i < n; ++i) { cin >> laziness[i]; minHeap.push(laziness[i]); } long long totalCost = 0; while (minHeap.size() > 1) { int first = minHeap.top(); minHeap.pop(); int second = minHeap.top(); minHeap.pop(); int mergeCost = first + second; totalCost += mergeCost; minHeap.push(mergeCost); } cout << totalCost << endl; return 0; }