grid and an integer budget. Consider the rectangles that start at the top-left cell (0, 0) and end at any cell (i, j).
Count how many of them have a total sum that **does not exceed** budget.grid=[[4, 3, 8], [2, 6, 1]], budget=10 → 3
The corner rectangle sums are 4, 7, 15 in the first row and 6, 15, 24 in the second. Three of them are at most 10.
grid=[[0, 0], [0, 5]], budget=4 → 3
Every rectangle except the full one (sum 5) fits the budget.
grid=[[9]], budget=3 → 0
grid=[[4, 3, 8], [2, 6, 1]], budget=10
3
Run checks the first 3 tests in your browser. Submit checks all 102 tests on the server, hidden ones included.