Convex hull tower cost
Your task
You must build a tower from a subset (in the given order) of n blocks. dp[i] is the minimum cost to end a valid build at block i, defined by dp[i] = min over j < i of (dp[j] + a[j] * b[i]) with dp[0] = 0, where a is non-increasing and b is non-decreasing (so the convex-hull / Li-Chao optimization applies). Return dp[n-1]. Inputs: arrays a and b of equal length n, with a[0] used as the base. Constraints: 1 <= n <= 100000, values fit in normal ints. A naive O(n^2) is too slow at the top range; the lines a[j]*x have non-increasing slopes queried at non-decreasing x.
Examples
min_build_cost(a: list[int], b: list[int]) -> intExample 1
Input
min_build_cost([5, 3, 2], [1, 2, 4])Output
20