Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
How to calculate the required sum for a cell (i,j) fast ?
Use the concept of cumulative sum array.
Create a cumulative sum matrix where dp[i][j] is the sum of all cells in the rectangle from (0,0) to (i,j), use inclusion-exclusion idea.