Level the Towers
Tower i is heights[i] floors high. Adding a floor to it or taking one off costs costs[i], every single time.
You want all towers to end at the same height. Return the least total cost.
Example 1
heights [1,4,6]
costs [5,1,1]
returns 8
Changing the first tower is dear, so the others come down to height 1: 3 floors and 5 floors at 1 each.
Example 2
heights [2,2,2]
costs [9,1,4]
returns 0
The towers are level already.
Example 3
heights [1,5]
costs [3,3]
returns 12
Any height from 1 to 5 costs 12: four floors have to change, at 3 each.
Constraints
1 <= len(heights) == len(costs) <= 301 <= heights[i] <= 10**61 <= costs[i] <= 10**6
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.