P1090 合并果子

#include <bits/stdc++.h>
using namespace std;
const int maxn = 10005;
int main(int argc, char const *argv[])
{
	int a[maxn];
	int n;
	cin >> n;
	priority_queue<int, vector<int>, greater<int> > q;
	for(int i = 1; i <= n; i++) {int x;cin >> x; q.push(x);}
	int ans = 0;
	while(q.size() > 1) {
		int x=q.top(); q.pop();
		int y=q.top(); q.pop();
		q.push(x+y);
		ans += x + y;
	}
	cout << ans;
	return 0;
}
原文地址:https://www.cnblogs.com/gengchen/p/6024520.html