Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional

You may increase any element of [2, 5, 3, 9] by 1 per operation, and you want all elements equal. What is the minimum number of operations?

  1. A. 17
  2. B. 9
  3. C. 36
  4. D. 7

Correct answer: A. 17

Values can only go up, so every element must rise to the maximum 9: (9 − 2) + (9 − 5) + (9 − 3) + 0 = 17. Moving everything to a median value costs 9 but needs decreases, 36 forgets to subtract the current sum, and 7 is just the largest gap.

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

Exams that ask this topic