Maximize Total Profit by Assigning Chefs to Dishes
Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem.
Problem
You are given three integer arrays:
chefSkill: each chef's skill leveldishDifficulty: each dish's difficultydishProfit: the profit earned for completing that dish
Rules:
- Each chef can complete at most one dish.
- A dish can be completed by multiple chefs (dishes are not exclusive).
- A chef can only complete a dish if
dishDifficulty[i] <= chefSkill[j]. - Each chef independently picks the most profitable dish they are able to complete.
- If a chef cannot complete any dish, they contribute 0 profit.
Compute the maximum total profit by assigning each chef the best dish they can do.
Input Format:
- Line 1: integer
nβ number of chefs - Line 2:
nspace-separated integers βchefSkill - Line 3: integer
mβ number of dishes - Line 4:
mspace-separated integers βdishDifficulty - Line 5:
mspace-separated integers βdishProfit
Output Format:
A single integer: the maximum total profit.
Example
Input:
3 1 2 3 3 1 2 3 1 2 3
Output:
6
Explanation: Chef with skill 1 picks dish with difficulty 1 (profit 1). Chef with skill 2 picks dish with difficulty 2 (profit 2). Chef with skill 3 picks dish with difficulty 3 (profit 3). Total = 6.
Task
Return the maximum total profit as an integer.
Complete solveMaximizeChefDishProfit. It has one parameter, String input, containing the full stdin payload. Return the stdout payload as an array of lines, without trailing newline characters.
input = "3\n1 2 3\n3\n1 2 3\n1 2 3" return = ["6"]
1 <= n, m <= 2 * 105dishDifficultyanddishProfitalways have the same lengthm.- All skill, difficulty, and profit values are non-negative integers.
- Arrays may be unsorted.
- If a chef's skill is less than all dish difficulties, that chef contributes 0 to the total profit.
public String[] solveMaximizeChefDishProfit(String input) {
// write your code here
}