Practice Maximum Sum With at Most K Elements
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Medium#3462
LeetCode ProblemMaximum Sum With at Most K Elements
Problem Statement
Given grid, limits, and k, select at most k matrix entries in total, taking at most limits[i] entries from row i. Return the maximum sum obtainable.
Source: Maximum Sum With at Most K Elements on LeetCode. Use the original task for its coding environment and submissions.
Examples
# 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))
Related LeetCode Problems
Practice more problems similar to Maximum Sum With at Most K Elements.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.