-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddAll.cpp
More file actions
35 lines (32 loc) · 690 Bytes
/
Copy pathAddAll.cpp
File metadata and controls
35 lines (32 loc) · 690 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
#include<stdio.h>
#include<functional>
#include<algorithm>
#include<queue>
#include<vector>
#include<iterator>
using namespace std;
int main(){
int bnykBilangan;
while(1){
int cummulativeSum = 0;
int minimumCost = 0;
scanf("%d",&bnykBilangan);
if(bnykBilangan == 0)break;
priority_queue<int, vector<int>, greater<int> > pQueue;//priorityQueue ascending..
for(int i = 0; i< bnykBilangan ; i++){
int input;
scanf("%d",&input);
pQueue.push(input);
}
while(pQueue.size() > 1){
int a = pQueue.top();
pQueue.pop();
int b = pQueue.top();
pQueue.pop();
minimumCost += a + b;
pQueue.push(a + b);
}
printf("%d\n",minimumCost);
}
return 0;
}