UVa 10954 - Add All

Summary
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
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.

Input
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
9 19 3400000 26