logo AlgoBeat OnlineJudge
登录 注册

#214922. [ICPC 2023 Yokohama R] Task Assignment to Two Employees

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Hanako is the CEO of a small company with two employees. She currently has some number of tasks and aims to earn some profits by making the employees do the tasks. Employees can enhance their skills through the tasks and, with higher skills, a larger profit can be earned from the same task. Thus, assigning tasks to appropriate employees in an appropriate order is important for maximizing the total profit.

For each pair of employee and task , two non-negative integers and are defined. Here, is the task compatibility and is the amount of skill growth. When task has been completed by employee whose skill point was , a profit of is earned, and his skill point increases to . Initially, both employees have skill points of .

Note that the skill points are individual, and completing a task by one employee does not change the skill point of the other. Each task must be done only once by only one employee. The order of tasks to carry out can be arbitrarily chosen.

输入格式

The input consists of a single test case of the following format.

All the input items are non-negative integers. The number of tasks satisfies . The initial skill point satisfies . Each is the amount of skill growth for the employee by completing the task , which satisfies . Each is the task compatibility of the employee with the task , which satisfies .

输出格式

Output the maximum possible total profit in one line.

样例

样例输入 1

4 0
10000 1 1 1
1 1 10000 1
1 10000 1 1
1 1 1 10000

样例输出 1

200000000

样例输入 2

3 1
1 1 1
2 2 2
2 2 2
1 1 1

样例输出 2

12