-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoiday1.cpp
More file actions
47 lines (45 loc) · 874 Bytes
/
noiday1.cpp
File metadata and controls
47 lines (45 loc) · 874 Bytes
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
//
// created by:DungTD
//
#include <bits/stdc++.h>
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define base int (1e9+7)
#define ll long long
using namespace std;
int a[1000006]={0};
struct cmp{
bool operator()(int a, int b) {return a>b;}
};
void solve(){
int n;
cin >> n;
int x;
priority_queue <int, vector<int>, cmp> pt;
for (int i=0; i<n; i++) {
cin >> x;
pt.push(x);
}
// while (!pt.empty()) {
// cout << pt.top() << " ";
// pt.pop();
// }
long long res = 0;
while (pt.size()>1) {
int tg = pt.top();
pt.pop();
tg+=pt.top();
pt.pop();
pt.push(tg);
res+=tg;
}
cout << res << endl;
}
int main(){
faster();
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}