[LeetCode] Find Minimum Log Transportation Cost

3560. Find Minimum Log Transportation Cost

You are given integers n, m, and k.

There are two logs of lengths n and m units, which need to be transported in three trucks where each truck can carry one log with length at most k units.

You may cut the logs into smaller pieces, where the cost of cutting a log of length x into logs of length len1 and len2 is cost = len1 * len2 such that len1 + len2 = x.

Return the minimum total cost to distribute the logs onto the trucks. If the logs don’t need to be cut, the total cost is 0.

1
2
3
4
5
6
7
8
9
10
func minCuttingCost(n, m, k int) int64 {
query := func(n, k int64) int64 {
if n <= k {
return 0
}
return k * (n - k)
}
kn := int64(k)
return query(int64(n), kn) + query(int64(m), kn)
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/05/25/PS/LeetCode/find-minimum-log-transportation-cost/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.