Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
Choose two NON-OVERLAPPING non-empty contiguous subarrays of [4, -1, 2, 6, -3, 5, -2] (the first must end before the second starts) and maximise the sum of their sums. What is the maximum?
- A. 16
- B. 13
- C. 26
- D. 12
Correct answer: A. 16
Prefix DP: best1[i] is the best subarray ending by i, best2[i] the best starting after i, and the answer combines them at each cut. Taking the two best subarrays independently can make them overlap, so the cut is essential.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- In how many ways can a 2 × 9 board be tiled exactly with 2 × 1 dominoes (placed vertically) and 2 × 2 squares, with no overlaps and no…
- How many integers x with 1 ≤ x ≤ 1000 are perfect squares or perfect cubes (or both)?
- Intervals (inclusive integer ranges) are [(1, 3), (2, 5), (4, 9), (6, 7), (8, 12), (9, 10)]. What is the minimum number of intervals whose…
- A binary string is "10110010". Flipping position i costs weight[i] = [3, 1, 4, 1, 5, 9, 2, 6]. You want the string to alternate (0101…
- How many contiguous subarrays of the binary array [1, 0, 1, 1, 0, 0, 1, 0] contain equally many 0s and 1s? (Non-empty subarrays only.)
- A string of brackets is ')))(()(' where '(' opens and ')' closes. What is the minimum number of brackets that must be removed to make the…