Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Equalize Array

med
30 min
Try to solve the Minimum Cost to Equalize Array problem.

Statement

You are given an integer array nums and two integers cost1 and cost2.

You can perform two types of operations on the array any number of times:

  • Choose an index i and increase nums[i] by 11 with a cost of cost1.

  • Choose two distinct indices i and j and increase both nums[i] and nums[j] by 11 with a cost of cost2.

Return the minimum cost to make all elements of nums equal. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6

  • 1≤1 \leq cost1 ≤106\leq 10^6

  • 1≤1 \leq cost2 ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Equalize Array

med
30 min
Try to solve the Minimum Cost to Equalize Array problem.

Statement

You are given an integer array nums and two integers cost1 and cost2.

You can perform two types of operations on the array any number of times:

  • Choose an index i and increase nums[i] by 11 with a cost of cost1.

  • Choose two distinct indices i and j and increase both nums[i] and nums[j] by 11 with a cost of cost2.

Return the minimum cost to make all elements of nums equal. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6

  • 1≤1 \leq cost1 ≤106\leq 10^6

  • 1≤1 \leq cost2 ≤106\leq 10^6