#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;
}

相关文章:

  • 2021-10-18
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2021-08-16
  • 2021-12-10
  • 2022-01-02
  • 2021-07-22
  • 2021-09-28
  • 2021-07-22
相关资源
相似解决方案