← 返回 amazon 的题目列表Minimal Cost to Make Sizes Distinct
类型:online_judge
One of the products listed on Amazon Ecommerce is available in n sizes indicated in the array size. The category manager recognizes that some of the sizes are repetitive and do not provide a good user experience. To make the best use of inventory, the product should be available in distinct sizes. The size of the ith product, size[i], can be increased by one unit for an amount in the cost array, cost[i].
Given the arrays size and cost for the product, find the minimal total cost in order to make all the sizes distinct.
Example
Given n = 4, size = [2, 3, 3, 2], and cost = [2, 4, 5, 1]
It costs 7 units to make the sizes distinct as follows:
Adjust size[1] to 5, which costs cost[1] * (5 - size[1]) = 8.
Adjust size[3] to 4, which costs cost[3] * (4 - size[3]) = 2.
Therefore, the total cost is 8 + 2 = 10.
However, the minimum cost required to make all sizes distinct is 7.
Function Description
Complete the function getMinimalCost with the following parameters:
int size[n]: the sizes of the product.
int cost[n]: the cost to change each size.
Returns:
long int: the minimal total cost to make all sizes distinct.
Constraints
1 <= n <= 2 * 10^5
1 <= size[i] <= 10^9
1 <= cost[i] <= 10^4
Example
Input
4
2 3 3 2
2 4 5 1