#1#2#3 RE求调
查看原帖
#1#2#3 RE求调
807378
Lee_OIer楼主2024/10/10 21:15
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[100010],ans=0;
priority_queue<ll,vector<ll>,greater<ll>> q1,q2;
int find_min(){
	int num; 
	if((! q1.empty() && q1.top() < q2.top()) || q2.empty()){
		num = q1.top();
		q1.pop();
	}
	else{
		num = q2.top();
		q2.pop();
	}
	return num;	
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    cin >> n;
    for(int i = 1 ; i <= n ; i++){
    	int num;
    	cin >> num;
    	a[num]++;
	}
	for(int i = 1 ; i <= 100000 ; i++) while(a[i]--) q1.push(i);
    while(! q1.empty() || q2.size() > 1){
    	int x,y;
    	x = find_min();
    	y = find_min();
    	ans += x + y;
		q2.push(x + y); 
	}
	cout << ans;
}

试着改了很多地方仍然为RE,#4TLE(目前还没写快读,写了应该就没问题了)

2024/10/10 21:15
加载中...