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]]?

  1. A. 8
  2. B. 5
  3. C. 4
  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.

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

Exams that ask this topic