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?
- A. 19
- B. 26
- C. 10
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many integers from 1 to 100 inclusive have an odd number of positive divisors?
- What is the length of the longest common substring (contiguous) of "abcdef" and "zcdemf"?
- When converting the infix expression "(a+b)(c-d)/e" to postfix, how many operator symbols appear in the postfix output?
- What is the sum of all odd positive divisors of 180?
- How many distinct sums arise from the length-3 windows of [1, 1, 2, 2, 3, 3, 1]?
- Among index pairs i < j of [-8, -3, -1, 2, 5, 9], how many pairs have the minimum possible absolute value of their sum?