Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum With at Most K Elements

Try to solve the Maximum Sum With at Most K Elements problem.

Statement

You are given an n $ imes$ m 2extD2 ext{D} 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

  • 1≤1 \leq n, m ≤500\leq 500

  • 0≤0 \leq grid[i][j] ≤105\leq 10^5

  • 0≤0 \leq limits[i] ≤\leq m

  • 0≤0 \leq k ≤min⁡(\leq \min(n $ imes$ m, $ ext{sum}(‘limits‘`limits`))$

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum With at Most K Elements

Try to solve the Maximum Sum With at Most K Elements problem.

Statement

You are given an n $ imes$ m 2extD2 ext{D} 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

  • 1≤1 \leq n, m ≤500\leq 500

  • 0≤0 \leq grid[i][j] ≤105\leq 10^5

  • 0≤0 \leq limits[i] ≤\leq m

  • 0≤0 \leq k ≤min⁡(\leq \min(n $ imes$ m, $ ext{sum}(‘limits‘`limits`))$