-
Notifications
You must be signed in to change notification settings - Fork 0
/
10954.cpp
54 lines (50 loc) · 816 Bytes
/
10954.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<sstream>
#define lli long long int
#define ulli unsigned long long int
#define rep(n) for(int i=0;i<n;i++)
#define iterate(x) for(auto itr=x.begin(); itr!=x.end();itr++)
using namespace std;
class op
{
public:
bool operator()(const int& a, const int& b)const {
return a > b;
}
};
int main()
{
int tc;
while (cin >> tc, tc != 0)
{
priority_queue<int, vector<int>, op> pq;
int n=tc, ans = 0;
rep(n)
{
int tmp;
cin >> tmp;
pq.push(tmp);
}
while (pq.size()!=1)
{
int sum = 0;
sum = pq.top();
pq.pop();
sum += pq.top();
pq.pop();
pq.push(sum);
ans += sum;
}
cout << ans << endl;
}
return 0;
}
//AC