- C20250174's blog
- 6999
- @ 2023-11-10 17:10:36
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
 
									//默认的小于关系 
priority_queue <int, vector<int> , greater<int>   > q;
int n , ans = 0; 
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		int k;
		scanf("%d",&k);
		q.push(k);
	}
	for (int i=1;i<=n-1;i++){	//做n-1次合并
		int x = q.top() ; q.pop();
		int y = q.top() ; q.pop();	//取出最小的两堆果子
	
		q.push( x + y);
		ans += x+y; 
	}
	cout << ans;
}
//每次找到当前最小的两堆果子并且合并 
