30pts求调
查看原帖
30pts求调
1706452
Ray_Peng楼主2025/7/19 10:57
#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int> >q;
queue<int>v;
int n,x;
long long ans=0;
void read(int &x){
	int f=1;
	char s=getchar();
	x=0;
	while(s<'0'||s>'9'){
        if(s=='-')f=-1;
        s=getchar();
    }
	while(s>='0'&&s<='9'){
        x=x*10+s-'0';
        s=getchar();
    }
	x*=f;
}
int main(){
    read(n);
	while(n--){
		read(x);
		q.push(x);
	}int a,b;
	while(q.size()>1){
		a=q.top();
		q.pop();
		b=q.top();
		q.pop();
		ans+=a+b;
		q.push(a+b);
	}
	cout<<ans;


	return 0;
}
2025/7/19 10:57
加载中...