60分求调
查看原帖
60分求调
998963
Tepley楼主2025/1/19 16:38
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const ll N = 1000005;
priority_queue<ll, vector<ll>, greater<ll> >a;
int main()
{
	ll n;
	ll c, x, y;
	ll k = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> c;
		a.push(c);
	}
	for (int i = 1; i <= n-1 ; i++)
	{
		x = a.top();
		a.pop();
		y = a.top();
		a.pop();
		a.push(x + y);
		k += x + y;
 
	}
	cout << k;
	return 0;
}
 
2025/1/19 16:38
加载中...