Under construction

Still being built. Things may change

Task Assignment to Two Employees

Time limit2sMemory limit1024 MB

Summary
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 nn 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 (i,j)(i, j) of employee ii and task jj, there are two non-negative integers vi,jv_{i,j} and si,js_{i,j}. Here, vi,jv_{i,j} is the task compatibility, and si,js_{i,j} is the amount of skill growth. When employee ii with skill point pp completes task jj, the employee earns a profit of p×vi,jp \times v_{i,j}, and the skill point increases to p+si,jp + s_{i,j}. Initially, both employees have skill point p0p_0.

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.

nn p0p_0

s1,1s_{1,1} ⋯\cdots s1,ns_{1,n}

s2,1s_{2,1} ⋯\cdots s2,ns_{2,n}

v1,1v_{1,1} ⋯\cdots v1,nv_{1,n}

v2,1v_{2,1} ⋯\cdots v2,nv_{2,n}

All input values are non-negative integers. The number of tasks nn satisfies 1≤n≤1001 \le n \le 100. The initial skill point p0p_0 satisfies 0≤p0≤1080 \le p_0 \le 10^8. Each si,js_{i,j} satisfies 0≤si,j≤1060 \le s_{i,j} \le 10^6, and each vi,jv_{i,j} satisfies 0≤vi,j≤1060 \le v_{i,j} \le 10^6.

Output

Output the maximum possible total profit on one line.

Examples2

  1. Example 1

    Input
    4 0
    10000 1 1 1
    1 1 10000 1
    1 10000 1 1
    1 1 1 10000
    
    Expected output
    200000000
    
  2. Example 2

    Input
    3 1
    1 1 1
    2 2 2
    2 2 2
    1 1 1
    
    Expected output
    12