Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Points with Cost

Try to solve the Maximum Number of Points with Cost problem.

Statement

You are given an m $ imes$ n integer matrix points with indices starting at 00. You want to maximize the total score obtained from the matrix.

To accumulate score, you must choose exactly one cell from each row. Choosing the cell at coordinate (r, c) adds points[r][c] to your score.

However, your score decreases if you choose a cell that is far from the cell chosen in the previous row. For every two adjacent rows r and r +1+ 1 (where 0≤0 \leq r <m−< m - 11), choosing cells at (r, c1) and (r +1+ 1, c2) subtracts ∣|c1 −- c2∣| from your score.

Return the maximum score you can achieve.

Constraints:

  • m ==== points.length

  • n ==== points[r].length

  • 1≤1 \leq m, n ≤105\leq 10^5

  • 1≤1 \leq m $ imes$ n ≤105\leq 10^5

  • 0≤0 \leq points[r][c] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Points with Cost

Try to solve the Maximum Number of Points with Cost problem.

Statement

You are given an m $ imes$ n integer matrix points with indices starting at 00. You want to maximize the total score obtained from the matrix.

To accumulate score, you must choose exactly one cell from each row. Choosing the cell at coordinate (r, c) adds points[r][c] to your score.

However, your score decreases if you choose a cell that is far from the cell chosen in the previous row. For every two adjacent rows r and r +1+ 1 (where 0≤0 \leq r <m−< m - 11), choosing cells at (r, c1) and (r +1+ 1, c2) subtracts ∣|c1 −- c2∣| from your score.

Return the maximum score you can achieve.

Constraints:

  • m ==== points.length

  • n ==== points[r].length

  • 1≤1 \leq m, n ≤105\leq 10^5

  • 1≤1 \leq m $ imes$ n ≤105\leq 10^5

  • 0≤0 \leq points[r][c] ≤105\leq 10^5