CodeTON Round 8 (Div. 1 + Div. 2, Rated, Prizes!) C2. Bessie’s Birthday Cake (Hard Version)
3139. Minimum Cost to Equalize Array
You are given an integer array
nums
and two integerscost1
andcost2
. You are allowed to perform either of the following operations any number of times:
- Choose an index
i
fromnums
and increasenums[i]
by1
for a cost ofcost1
.- Choose two different indices
i
,j
, fromnums
and increasenums[i]
andnums[j]
by1
for a cost ofcost2
.Return the minimum cost required to make all elements in the array equal*.*
Since the answer may be very large, return it modulo
109 + 7
.