Problem · Tree
Maximize Happiness
Learn this problemProblem statement
Employees form a rooted company tree. Row i of employeeData is [manager, cost, leadership] for employee i + 1. Manager 0 marks the root.
Choose one employee as the manager for a client, then hire any subset of employees in that manager's subtree. The chosen manager may be hired, but does not have to be. The total hiring cost must not exceed budget.
The client's happiness is:
chosen manager's leadership * number of hired employees.
Return the maximum possible happiness.
Function
maximizeHappiness(employeeData: int[][], budget: int) → longExamples
Example 1
employeeData = [[0, 10, 400], [1, 10, 300], [2, 15, 100], [1, 10, 60], [1, 15, 800], [2, 5, 100], [2, 5, 100]]budget = 20return = 1200Choose employee 1 as manager and hire employees 2, 6, 7. Their total cost is 20, so happiness is 400 * 3 = 1200.