-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10954.cpp
More file actions
51 lines (45 loc) · 1.02 KB
/
10954.cpp
File metadata and controls
51 lines (45 loc) · 1.02 KB
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
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
#define lli long long int
lli arr[100010];
priority_queue<lli, vector<lli>,greater<lli> >pq;
int main(){
lli n,tot,tmp,a;
while(cin>>n){
if(n==0) break;
for(int i=0;i<n;i++){
scanf("%lld",&a);
pq.push(a);
}
//sort(arr,arr+n);
/*tot = arr[0] + arr[1];
tmp = tot;
for(int i=2;i<n;i++){
tot = tot + arr[i];
tmp = tmp + tot ;
//tmp = tot;
}*/
tmp = 0;
tot = pq.top();
pq.pop();
tot = tot + pq.top();
pq.pop();
tmp = tot;
pq.push(tot);
while(pq.size()>1){
tot = pq.top();
pq.pop();
//cout<<tot<<endl;
tot = tot + pq.top();
pq.pop();
//cout<<tot<<endl;
tmp += tot;
pq.push(tot);
}
cout<<tmp<<endl;
while(!pq.empty()) pq.pop();
}
}