Minimum Project Bid Cost
Problem statement
There are numProjects projects numbered from 0 to numProjects - 1. Two arrays describe the submitted bids: bid i offers to complete project projectId[i] for a cost of bid[i].
Choose one bid for every project to minimize the total cost. Each bid applies only to its listed project, and choices for different projects are independent.
Return the minimum total cost. If any project has no bid, return -1.
Function
minimumProjectBidCost(numProjects: int, projectId: int[], bid: int[]) → longExamples
Example 1
numProjects = 3projectId = [0,1,0,2,1]bid = [8,5,3,7,9]return = 15The lowest bids for projects 0, 1, and 2 are 3, 5, and 7. Their total is 15.
Example 2
numProjects = 3projectId = [0,2,0]bid = [4,6,2]return = -1Project 1 has no bid, so it is impossible to cover every project. Return -1.
Example 3
numProjects = 2projectId = [1,0,1]bid = [0,9,4]return = 9Choose the bid of 9 for project 0 and the bid of 0 for project 1. The total is 9.
Constraints
1 <= numProjects <= 10^50 <= projectId.length <= 10^5projectId.length == bid.length0 <= projectId[i] < numProjects0 <= bid[i] <= 10^9