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?
- A. 17
- B. 9
- C. 36
- 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.
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
- In the binary row [1, 1, 0, 1, 1, 1] treated as a histogram of height 1, what is the largest rectangle area?
- What is the length of the shortest contiguous subarray of [5, 1, 4, 3, 2, 6, 7] whose sum is at least 15?
- In [6, 3, 6, 9, 3, 9, 9, 5, 5] exactly one value appears an odd number of times and every other value appears an even number of times…
- How many index pairs i < j in [12, 21, 30, 43, 66, 111, 3] have equal decimal digit sums?
- How many ordered index pairs (i, j) in [1, 3, 4, 7, 10, 12, 15] satisfy a[j] - a[i] = 3?
- How many integers from 1 to 10000 inclusive are multiples of 7 whose decimal digit sum is exactly 7?