Data Structures & AlgorithmsVery hardCodeforces Div2 D

You split the array [1, 15, 7, 9, 2, 5, 10] into contiguous non-empty segments, each of length at most 3. A segment contributes (its maximum) × (its length). What is the largest total you can get?

  1. A. 82
  2. B. 75
  3. C. 84
  4. D. 90

Correct answer: C. 84

dp[i] is the best total for the prefix of length i; the last segment has length 1 to 3 and value (its maximum) × (its length). Cutting fixed blocks of 3 from the left is not optimal, because where the cut falls matters.

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

Exams that ask this topic