You are given an n m 2D integer matrix grid, an integer array limits of length n, and an integer k.
Your task is to select at most k elements from grid such that the number of elements chosen from row i does not exceed limits[i].
Return the maximum possible sum of the chosen elements.
Constraints:
n grid.length limits.length
m grid[i].length
n, m
grid[i][j]
limits[i] m
k n m, sum(limits)
You are given an n m 2D integer matrix grid, an integer array limits of length n, and an integer k.
Your task is to select at most k elements from grid such that the number of elements chosen from row i does not exceed limits[i].
Return the maximum possible sum of the chosen elements.
Constraints:
n grid.length limits.length
m grid[i].length
n, m
grid[i][j]
limits[i] m
k n m, sum(limits)