mediumArrayGreedyHeap Priority QueueMatrixSorting 0 views
Maximum Sum With at Most K Elements
You are given a 2D integer matrix grid of size n x m, an integer array limits of length n, and an integer k.
You are given a 2D integer matrix grid of size n x m, an integer array limits of length n, and an integer k. The task is to find the maximum sum of at most k elements from the matrix grid such that:
Return the maximum sum.
Example 1
Input: grid = [[1,2],[3,4]], limits = [1,2], k = 2
Output: 7
Example 2
Input: grid = [[5,3,7],[8,2,6]], limits = [2,2], k = 3
Output: 21
Constraints
- n == grid.length == limits.length
- m == grid[i].length
- 1 <= n, m <= 500
- 0 <= grid[i][j] <= 10^5
- 0 <= limits[i] <= m
- 0 <= k <= min(n * m, sum(limits))
Hints
Companies
No companies reported yet.
Discussion
Sign in to join the discussion.
Loading discussion...
Test results
No test cases yet.