ans

caochenshuo 2023-11-25 13:18:12 3 返回题目

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,s;
priority_queue<int> q;
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k;
		q.push(-k);
	}
	while(q.size()>=2){
		int a=-q.top();
		q.pop();
		int b=-q.top();
		q.pop();
		s=s+a+b;
		q.push(-(a+b));
	}
	cout<<s<<endl;
	return 0;
}
{{ vote && vote.total.up }}