Maximum sum rectangle bounded

Write codeHard45 min

Your task

Given an m x n integer matrix and an integer k, find the maximum sum of a rectangular submatrix such that the sum is no larger than k. It is guaranteed that at least one such submatrix exists. Return that maximum sum (which may be negative).

Examples

max_sum_submatrix(matrix: list[list[int]], k: int) -> int
Example 1
Inputmax_sum_submatrix([[1, 0, 1], [0, -2, 3]], 2)
Output2