Task Assignment to Two Employees
Time limit2sMemory limit1024 MB
Assign each of n tasks to one of two employees and pick the order so that total profit, where skill points grow with each completed task, is maximized.
- Level
Hard8 of 10
- Topics
- Graph, Dynamic programming
- Solved
- No attempts yet
Problem
Hanako is the CEO of a small company with two employees. She currently has tasks and wants to earn profits by having the employees do them. Employees can build their skills through tasks, and with higher skill points, they earn a larger profit from the same task. Assigning tasks to the right employee in the right order is therefore important for maximizing the total profit.
For each pair of employee and task , there are two non-negative integers and . Here, is the task compatibility, and is the amount of skill growth. When employee with skill point completes task , the employee earns a profit of , and the skill point increases to . Initially, both employees have skill point .
Skill points are tracked separately for each employee. When one employee completes a task, the other employee's skill point does not change. Each task must be done exactly once by exactly one employee. You can choose the order of the tasks freely.
Input
The input consists of a single test case in the following format.
All input values are non-negative integers. The number of tasks satisfies . The initial skill point satisfies . Each satisfies , and each satisfies .
Output
Output the maximum possible total profit on one line.