ans

wyz2011 2023-11-25 16:13:03 4 返回题目

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