Skip to content

Practice Minimum Cost for Cutting Cake II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3219
LeetCode Problem

Minimum Cost for Cutting Cake II

Problem Statement

An m by n cake must be divided into unit squares. horizontalCut[i] gives the fixed cost of cutting along horizontal grid line i, and verticalCut[j] gives the fixed cost for vertical grid line j. One operation cuts a single existing piece along one of those lines into two pieces and pays that line’s cost. Reusing a line on another piece incurs its cost again. Return the minimum total cost to produce all 1 by 1 pieces.

Source: Minimum Cost for Cutting Cake II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]
Output
13

# Example 2

Input
m = 2, n = 2, horizontalCut = [7], verticalCut = [4]
Output
15

Constraints

1 <= m, n <= 10^5
horizontalCut.length == m - 1
verticalCut.length == n - 1
1 <= horizontalCut[i], verticalCut[i] <= 10^3

Related LeetCode Problems

Practice more problems similar to Minimum Cost for Cutting Cake II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.