OA test Atlassian || ON campus || 16/08/2022 at 7 pm
Anonymous User
951

image
image
image
image

Question 1. Freelancing Platform A customer has posted several web development projects on a freelancing platform, and various web developers have put in bids for these projects. Given the bid amounts and their corresponding projects, what is the minimum amount the customer can pay to have all the projects completed? Note: If any project has no bids, return -1. Example numProjects = 3 projects. projectld = (2,0, 1, 2] bid = [8, 7, 6, 9]. • projectld[i] is aligned with bidii] • The first web developer bid 8 currency units for project 2. • The second web developer bid 7 currency units for project 0. • The third web developer bid 6 currency units for project 1. • The fourth web developer bld 9 currency units for project 2. There is only one choice of who to hire for project 0, and it will cost 7. Likewise, there is only one choice for project 1, which will cost 6. For project 2 it is optimal to hire the first web developer, instead of the fourth, and doing so will cost 8. So the final answer is 7 + 6 + 8 = 21. If instead there were n = 4 projects, the answer would be since there were no bids If instead there were n = 4 projects, the answer would be -1 since there were no blds received on the fourth project. Function Description Complete the function minCost in the editor below. minCost has the following parameters: int numProjects the total number of projects posted by the client (labeled from 0 ton) Int projectldin): an array of Integers denoting the projects that the freelancers bid on int bidan): an array of Integers denoting the bid amounts posted by the freelancers Returns: long the minimum cost the client can spend to complete all projects, or -1 if any project has no bids. Constraints 1 s numProjects, ns 5x105 Os projectldi<n 1 s bid[i] s 10° . Input Format For Custom Testing The first line contains an Integer, num Projects. The next line contains an integer, n, which denotes the number of elements in array projectld). Each line i of the n subsequent lines (where 0 si<n) contains an integer, projectld[i]. The next line contains an integer, n, which denotes the number of elements in array bid. Each line i of the n subsequent lines (where Osi<n) contains an integer, bid[i]. Sample Case o Sample Input STDIN Function ---- 2 5 → numProjects = 2 projectId[] size n = 5 projectId = [0, 1, 0, 1, 1] 0 → 1 1 1 5 → bid[] size n = 5 bid = [4, 74, 47, 744, 7] 4 74 47 744 7 Sample Output 11 Explanation The bids are as follows: • The first web developer bid 4 currency units for project 0. • The second web developer bld 74 currency units for project 1. • The third web developer bid 47 currency units for project 0. The fourth web developer bid 744 currency units for proiect 1 • The second web developer bld 74 currency units for project 1. • The third web developer bld 47 currency units for project 0. • The fourth web developer bld 744 currency units for project 1. • The fifth web developer bid 7 currency units for project 1. The optimal solution is to hire the first web developer to complete project (which costs 4) and to hire the fifth web developer to complete project 1 (which costs 7). This brings the total cost to 11. Sample Case 1 Sample Input STDIN Function 2. 2. numProjects = 2 projectId[] size n = 2 → projectId = [1, 1] 1 1 2 bid[] size n = 2 bid = [4, 7] 4 > 7 Sample Output -1 Explanation Because there are no bids for project 0, the function should return -1.

Comments (3)