Find Minimum Log Transportation Cost - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
n = 7, m = 4, k = 3
›
Output:
21
💡 Note:
Log n=7: Cut into pieces [3,3,1]. Cost = 3×4 + 3×1 = 15. Log m=4: Cut into pieces [3,1]. Cost = 3×1 = 3. Total = 15 + 6 = 21.
Example 2 — No Cuts Needed
$
Input:
n = 3, m = 2, k = 5
›
Output:
0
💡 Note:
Both logs fit in trucks without cutting since 3 ≤ 5 and 2 ≤ 5. Total cost = 0.
Example 3 — One Log Needs Cutting
$
Input:
n = 8, m = 3, k = 4
›
Output:
16
💡 Note:
Log n=8: Cut into [4,4]. Cost = 4×4 = 16. Log m=3: No cut needed. Total = 16.
Constraints
- 1 ≤ n, m, k ≤ 1000
- We have exactly 3 trucks available
- Each truck can carry at most one log
Visualization
Tap to expand
Understanding the Visualization
1
Input
Two logs of lengths n=7, m=4 with truck capacity k=3
2
Process
Cut logs to fit: minimize total cutting cost
3
Output
Minimum cost = 21
Key Takeaway
🎯 Key Insight: Cut pieces of maximum size k from the end to minimize total cost
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code