Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Make Array Equal

Minimum Cost to Make Array Equal asks you to choose a common value for an array, where each one-unit increase or decrease costs its element's rate, and return the least total cost.

Statement

You are given two 00 indexed integer arrays nums and cost, both of length n.

In one operation, you can increase or decrease any element nums[i] by 11. The cost of performing this operation on nums[i] is cost[i].

Return the minimum total cost to make all elements in nums equal.

Constraints:

  • n ==== nums.length ==== cost.length

  • 1≤1 \leq n ≤105\leq 10^5

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

  • The test cases are generated such that the minimum cost does not exceed 253−12^{53} - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Make Array Equal

Minimum Cost to Make Array Equal asks you to choose a common value for an array, where each one-unit increase or decrease costs its element's rate, and return the least total cost.

Statement

You are given two 00 indexed integer arrays nums and cost, both of length n.

In one operation, you can increase or decrease any element nums[i] by 11. The cost of performing this operation on nums[i] is cost[i].

Return the minimum total cost to make all elements in nums equal.

Constraints:

  • n ==== nums.length ==== cost.length

  • 1≤1 \leq n ≤105\leq 10^5

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

  • The test cases are generated such that the minimum cost does not exceed 253−12^{53} - 1