Three Ranges One Pass

An array of eight zeros, indexed 1 through 8, receives three range updates. Using a difference array d, an update that adds v to every element in [l, r] is recorded as d[l] += v and d[r + 1] -= v; the final array is the prefix sum of d.

Updates, in order:

  1. add 3 to [2, 5]
  2. add 5 to [4, 7]
  3. add -2 to [1, 3]

What is the final array?

A

[0, -2, 1, 3, 8, 5, 5, 0]

B

[-2, 1, 1, 8, 8, 5, 5, 0]

C

[-2, 1, 3, 8, 5, 5, 0, 0]

D

[-2, 3, 0, 7, 0, -3, 0, -5]