UVa 10954 - Add All

10954 - Add All

 * http://acm.uva.es/p/v109/10954.html

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