re求调
查看原帖
re求调
1044461
liguanda楼主2024/5/26 16:29
#include <bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int>> pq;
long long x;
long long a,s,ans,d;
int main (){
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> x;
		pq.push(x);
		}
		for (int i = 1; i <= n; i++){
		a=pq.top();
		pq.pop();
		s=pq.top();
		pq.pop();
		d=a+s;
		pq.push(d);
		ans+=d;
		}
		cout << ans << endl;
	return 0;
}
2024/5/26 16:29
加载中...