这题是不是用不了快读,样例都过,但是0
查看原帖
这题是不是用不了快读,样例都过,但是0
448552
dong154707974楼主2023/11/17 21:04
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int re()
{
	int x=0;
	char y=getchar();
	while(y>='0'&&y<='9')x=(x<<3)+(x<<1)+y-'0',y=getchar();
	return x;
}
priority_queue <int,vector<int>,greater<> > q;
int main(){
	int n,ans=0,z;
	n=re();
	for(int i=1;i<=n;i++)
	{
		z=re();
		q.push(z);
	}
	for(int i=1;i<=n-1;i++)
	{
		int x=q.top(),temp;
		q.pop();
		int y=q.top();
		q.pop();
		temp=x+y;
		ans+=temp;
		q.push(temp);
	}
	cout<<ans<<endl;
}
2023/11/17 21:04
加载中...