Data Structures & AlgorithmsVery hardCodeforces Div2 D · GATE CS

Choose a subsequence of length exactly 3 from [5, 1, 4, 2, 6, 3, 7, 2] (keeping order) whose elements are non-decreasing. What is the maximum possible sum?

  1. A. 13
  2. B. 20
  3. C. 18
  4. D. 19

Correct answer: C. 18

Use a DP over (index, length) with the non-decreasing constraint, taking the best predecessor with a smaller or equal value. Choosing the k largest values ignores the order requirement.

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

Exams that ask this topic