3462. Maximum Sum With at Most K Elements
You are given a 2D integer matrix
grid
of sizen x m
, an integer arraylimits
of lengthn
, and an integerk
. The task is to find the maximum sum of at mostk
elements from the matrixgrid
such that:
- The number of elements taken from the
ith
row ofgrid
does not exceedlimits[i]
.Return the maximum sum.
c++
1 | class Solution { |