Class Solution
-
- All Implemented Interfaces:
public final class Solution3560 - Find Minimum Log Transportation Cost.
Easy
You are given integers
n,m, andk.There are two logs of lengths
nandmunits, which need to be transported in three trucks where each truck can carry one log with length at mostkunits.You may cut the logs into smaller pieces, where the cost of cutting a log of length
xinto logs of lengthlen1andlen2iscost = len1 * len2such thatlen1 + 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.
Example 1:
Input: n = 6, m = 5, k = 5
Output: 5
Explanation:
Cut the log with length 6 into logs with length 1 and 5, at a cost equal to
1 * 5 == 5. Now the three logs of length 1, 5, and 5 can fit in one truck each.Example 2:
Input: n = 4, m = 4, k = 6
Output: 0
Explanation:
The two logs can fit in the trucks already, hence we don't need to cut the logs.
Constraints:
<code>2 <= k <= 10<sup>5</sup></code>
1 <= n, m <= 2 * kThe input is generated such that it is always possible to transport the logs.