Imagine you have an array of integers where each element represents the height of a tower. Your goal is to make all towers the same height using the most cost-effective strategy possible.
You have two operations at your disposal:
- Operation 1: Increase any single tower's height by 1 for a cost of
cost1 - Operation 2: Increase any two different towers' heights by 1 each for a cost of
cost2
The challenge is to determine the minimum total cost to equalize all towers to the same height. Since costs can become astronomical for large arrays, return your answer modulo 109 + 7.
Example: If you have towers [1, 3, 4] and cost1 = 2, cost2 = 3, you need to raise the first tower by 3 and second tower by 1. You could use operation 1 four times (cost = 8) or mix operations for potentially lower cost.
Input & Output
Constraints
- 1 β€ nums.length β€ 105
- 1 β€ nums[i] β€ 106
- 1 β€ cost1, cost2 β€ 106
- Result must be returned modulo 109 + 7