Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

Repeatedly merge two values into their sum at cost equal to that sum, starting from [1, 2, 3, 4]. What is the minimum total cost?

  1. A. 19
  2. B. 26
  3. C. 10
  4. D. 29

Correct answer: A. 19

Always merge the two smallest (Huffman): 1+2 = 3, 3+3 = 6, 6+4 = 10, total cost 3 + 6 + 10 = 19. Merging the largest first costs 26, 10 is only the final value, and 29 also adds the starting values as if they had a cost.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic