UVa 10954

From Algorithmist
Jump to navigation Jump to search

10954 - Add All[edit]

Summary[edit]

Using a Priority Queue, you can greedily take the two smallest numbers, add them and insert them back into the Priority Queue. This is similar to the Huffman algorithm.

Explanation[edit]

Using a Priority Queue, you can greedily take the two smallest numbers, add them and insert them back into the Priority Queue. This is similar to the Huffman algorithm.

Solutions[edit]

Input[edit]

3
1 2 3
4
1 2 3 4
10
100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 
5 
2 2 2 2 3
0

Output[edit]

9
19
3400000
26