Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
For a given range of values in target, an optimal strategy is to increment the entire range by the minimum value. The minimum in a range could be obtained with Range minimum query or Segment trees algorithm.