为什么WA???
查看原帖
为什么WA???
1051280
ccc08080楼主2025/8/1 20:48
#include<bits/stdc++.h>
using namespace std;
void read(int &x){ 
	int f=1;x=0;char s=getchar();
	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;
}
long long a,s[10000100],d[100100],f,g,h,j,k;
long long M=100000000000000000000;
queue<int> q1;
queue<int> q2;
int main(){
	cin>>a;
	if(a==0){
		cout<<0;
		return 0;
	}
	for(long long i=1;i<=a;i++){
		int l;
		read(l);
		d[l]++;
		
	}
	for(int i=1;i<=100000;i++){
		while(d[i]){
			d[i]--;
			q1.push(i);
		}
	}
	cnt=1;
	k=0;
	for(long long i=1;i<a;i++){
		f=min(((!q1.empty())?(q1.front()):M),((!q2.empty())?(q2.front()):M));
		if(f==q1.front()) q1.pop();
		else q2.pop();
		g=min(((!q1.empty())?(q1.front()):M),((!q2.empty())?(q2.front()):M));
		if(g==q1.front()) q1.pop();
		else q2.pop();
		h=f+g;
		q2.push(h);
		k+=h;
	}
	cout<<k;
}
2025/8/1 20:48
加载中...