Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Equalize Array

Minimum Cost to Equalize Array asks you to raise an array until all values match, using single-element or two-distinct-element increments with costs, then return the minimum modulo a large prime.

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

Minimum Cost to Equalize Array asks you to raise an array until all values match, using single-element or two-distinct-element increments with costs, then return the minimum modulo a large prime.

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