FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 3402,3 "name": "minimum-cost-to-equalize-array",4 "difficulty": "Hard",5 "link": "https://leetcode.com/problems/minimum-cost-to-equalize-array/",6 "date": "2024-04-28",7 "task_description": "You are given an integer array `nums` and two integers `cost1` and `cost2`. You are allowed to perform **either** of the following operations **any** number of times: Choose an index `i` from `nums` and **increase** `nums[i]` by `1` for a cost of `cost1`. Choose two **different** indices `i`, `j`, from `nums` and **increase** `nums[i]` and `nums[j]` by `1` for a cost of `cost2`. 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`. **Example 1:** **Input:** nums = [4,1], cost1 = 5, cost2 = 2 **Output:** 15 **Explanation: ** The following operations can be performed to make the values equal: Increase `nums[1]` by 1 for a cost of 5. `nums` becomes `[4,2]`. Increase `nums[1]` by 1 for a cost of 5. `nums` becomes `[4,3]`. Increase `nums[1]` by 1 for a cost of 5. `nums` becomes `[4,4]`. The total cost is 15. **Example 2:** **Input:** nums = [2,3,3,3,5], cost1 = 2, cost2 = 1 **Output:** 6 **Explanation: ** The following operations can be performed to make the values equal: Increase `nums[0]` and `nums[1]` by 1 for a cost of 1. `nums` becomes `[3,4,3,3,5]`. Increase `nums[0]` and `nums[2]` by 1 for a cost of 1. `nums` becomes `[4,4,4,3,5]`. Increase `nums[0]` and `nums[3]` by 1 for a cost of 1. `nums` becomes `[5,4,4,4,5]`. Increase `nums[1]` and `nums[2]` by 1 for a cost of 1. `nums` becomes `[5,5,5,4,5]`. Increase `nums[3]` by 1 for a cost of 2. `nums` becomes `[5,5,5,5,5]`. The total cost is 6. **Example 3:** **Input:** nums = [3,5,3], cost1 = 1, cost2 = 3 **Output:** 4 **Explanation:** The following operations can be performed to make the values equal: Increase `nums[0]` by 1 for a cost of 1. `nums` becomes `[4,5,3]`. Increase `nums[0]` by 1 for a cost of 1. `nums` becomes `[5,5,3]`. Increase `nums[2]` by 1 for a cost of 1. `nums` becomes `[5,5,4]`. Increase `nums[2]` by 1 for a cost of 1. `nums` becomes `[5,5,5]`. The total cost is 4. **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i] <= 106` `1 <= cost1 <= 106` `1 <= cost2 <= 106`",8 "test_case": [9 {10 "label": "Example 1",11 "input": "nums = [4,1], cost1 = 5, cost2 = 2",12 "output": "15 "13 },14 {15 "label": "Example 2",16 "input": "nums = [2,3,3,3,5], cost1 = 2, cost2 = 1",17 "output": "6 "18 },19 {20 "label": "Example 3",21 "input": "nums = [3,5,3], cost1 = 1, cost2 = 3",22 "output": "4 "23 }24 ],25 "constraints": [26 "Choose an index i from nums and increase nums[i] by 1 for a cost of cost1.",27 "Choose two different indices i, j, from nums and increase nums[i] and nums[j] by 1 for a cost of cost2.",28 "Increase nums[1] by 1 for a cost of 5. nums becomes [4,2].",29 "Increase nums[1] by 1 for a cost of 5. nums becomes [4,3].",30 "Increase nums[1] by 1 for a cost of 5. nums becomes [4,4].",31 "Increase nums[0] and nums[1] by 1 for a cost of 1. nums becomes [3,4,3,3,5].",32 "Increase nums[0] and nums[2] by 1 for a cost of 1. nums becomes [4,4,4,3,5].",33 "Increase nums[0] and nums[3] by 1 for a cost of 1. nums becomes [5,4,4,4,5].",34 "Increase nums[1] and nums[2] by 1 for a cost of 1. nums becomes [5,5,5,4,5].",35 "Increase nums[3] by 1 for a cost of 2. nums becomes [5,5,5,5,5].",36 "Increase nums[0] by 1 for a cost of 1. nums becomes [4,5,3].",37 "Increase nums[0] by 1 for a cost of 1. nums becomes [5,5,3].",38 "Increase nums[2] by 1 for a cost of 1. nums becomes [5,5,4].",39 "Increase nums[2] by 1 for a cost of 1. nums becomes [5,5,5].",40 "1 <= nums.length <= 105",41 "1 <= nums[i] <= 106",42 "1 <= cost1 <= 106",43 "1 <= cost2 <= 106"44 ],45 "python_template": "class Solution(object):\n def minCostToEqualizeArray(self, nums, cost1, cost2):\n \"\"\"\n :type nums: List[int]\n :type cost1: int\n :type cost2: int\n :rtype: int\n \"\"\"\n ",46 "java_template": "class Solution {\n public int minCostToEqualizeArray(int[] nums, int cost1, int cost2) {\n \n }\n}",47 "metadata": {48 "func_name": "minCostToEqualizeArray"49 }50}