2. Question 2 ALL 1 2 There exist n microservices, each with a specific number of…
- User
- Question 2
ALL
1
2
There exist n microservices, each with a specific number of running pods denoted by pods[i] for every 1 <= i <= n It is essential for these microservices to maintain a pairwise distinct number of running pods. To accomplish this, the following action can be taken:
Select any microservice indexed as ith and raise its running pod count by 1. The expense associated with this action is defined as cost[i].
Determine the minimum cost necessary to meet this stipulated criterion.
3
Example
Given that n = 5 the array pods = [5, 2, 5, 3, 3] , and cost = [3, 7, 8, 6, 9],
The optimal sequence of operations is as follows:
Select pods[0] = 5 and increment it by 1, incurring a cost of 3. This results in pods = [6, 2, 5, 3, 3]
• Choose pods[3] = 3 and increase it by 1, with a cost of 6. Consequently, pods = [6, 2, 5, 4, 3]
Therefore, the array pods = [6, 2, 5, 4, 3] contains pairwise distinct numbers of active pods. The total cost amounts to 3 + 6 = 9 representing the minimum possible expenditure. Function Description
Complete the function getMinCost in the editor below.
getMinCost has the following parameter(s):
int pods[n]: the number of running pods for each micro-service
ALL
1
2
int cost[n]: the cost of increasing the number of running pods for each micro-service
Returns
long: the minimum possible cost to make the number of running pods for each micro-service pairwise distinct.
Constraints
• 1≤ n ≤10^5
1 s pods[i] ≤ 10^9
1 ≤ cost[i] ≤ 10^5
▼ Sample Case 0
Sample Input For Custom Testing Stdin function 3-> pods[] size n=3 8-> pods= [8,6,8] 6 8 pods[] size n=3 3pods= [9,5,7] 9 5 7
Output 7 Explanation
An ideal sequence of operations is as follows:
Start by selecting pods[2] = 8 and increment it by 1, incurring a cost of 7. Consequently, pods becomes [8, 6, 9].
The array pods = [8, 6, 9] comprises pairwise distinct number of active pods. C++
- Assistant