30玄关
查看原帖
30玄关
978486
ca0vnv楼主2024/8/24 14:41
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
priority_queue<ll,vector<ll>,greater<ll> > a;
int main(){  
	long long ans=0,n,t;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t;
		a.push(t);
	}
	for(int i=1;i<=n-1;i++){
		int c,d;
		c=a.top();
		a.pop();
		d=a.top();
		a.pop();
		ans+=c+d;
		a.push(c+d);
	}
	cout<<ans<<endl;
	return 0;
}

2024/8/24 14:41
加载中...