Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional

In one operation you may choose a contiguous subarray and increase every element in it by 1. Starting from [0, 0, 0, 0], what is the minimum number of operations needed to reach [3, 1, 2, 4]?

  1. A. 10
  2. B. 6
  3. C. 4
  4. D. 8

Correct answer: B. 6

The minimum number of range increments to build a target from zeros is the sum of the positive jumps t[i] − t[i−1] (with t[0] counted from zero). Summing the values, or taking the maximum, counts the same increment many times.

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

Exams that ask this topic