Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
What is the maximum possible sum of entries of a non-empty contiguous rectangular submatrix of [[1, -2, 3, 0], [-1, 4, -2, 2], [2, -3, 5, -1]]?
- A. 8
- B. 5
- C. 4
- D. 9
Correct answer: A. 8
Fix a pair of rows, collapse the columns into a 1D array, and run Kadane's algorithm on it: O(R²·C) overall. Considering only single rows or the best single cell misses the rectangles that cross rows.
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
- A fence has 5 posts and each post is painted one of k = 3 colours. No three consecutive posts may share the same colour. How many…
- Target string "abcbc" must be built by concatenating words from the list ['ab', 'bc', 'abc', 'a', 'b', 'c', 'cb']; each word can be…
- A truck carries at most 5 boxes. Box types are given as (number of boxes of this type, units per box): [(1, 3), (2, 2), (3, 1), (2, 4)]…
- How many contiguous subarrays of 2 3 4 1 6 9 have a product divisible by 6?
- How many contiguous subarrays of 5 2 7 1 8 3 6 4 have an ODD length and a sum divisible by 7?
- What is the sum, over all non-empty contiguous subarrays of 5 3 6 1 4, of their XOR values, taken modulo 1000?