Selasa, 27 Desember 2016

UVA 10954 - Add All Solution

Problem Statement: Add All

Explanation

This problem can be solved easily by using Java PriorityQueue.

  • Insert all input to PriorityQueue and create variable "sum" to store the final result.
  • Take 2 item from the queue and store the sum result of those 2 item in variable "temp".
  • Add "temp" to "sum.
  • Finally insert "temp" back to queue and repeat the process above until there's only 1 item in queue.
Source Code

Tidak ada komentar:

Posting Komentar