PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000323. Phân công nhiều việc nhất (Maximum Number of Tasks You Can Assign)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phân công nhiều việc nhất (Maximum Number of Tasks You Can Assign)

Maximum Number of Tasks You Can Assign

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn tasks and mm workers. Task ii requires strength at least aia_i; worker jj initially has strength bjb_j.

You may distribute up to pp pills. Each pill adds ss units of strength to its recipient, and no worker may receive more than one pill.

A worker can perform at most one task, and a task can be assigned to at most one worker. An assignment is valid only if the worker's resulting strength meets the task's requirement. Determine the maximum number of tasks that can be completed.

Input

  • The first line contains four integers n,m,p,sn,m,p,s: the number of tasks, workers, pills, and the strength increase per pill.
  • The second line contains nn integers a1,…,ana_1,\ldots,a_n, the task requirements.
  • The third line contains mm integers b1,…,bmb_1,\ldots,b_m, the initial worker strengths.

Output

Print one integer: the maximum number of completed tasks.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤81\le n,m\le8; 0≤p≤m0\le p\le m; 0≤ai,bj,s≤200\le a_i,b_j,s\le20.
  • Subtask 2 (30 points): 1≤n,m≤5⋅1041\le n,m\le5\cdot10^4; 0≤p≤m0\le p\le m; 0≤ai,bj,s≤1090\le a_i,b_j,s\le10^9; p=0p=0.
  • Subtask 3 (50 points): 1≤n,m≤5⋅1041\le n,m\le5\cdot10^4; 0≤p≤m0\le p\le m; 0≤ai,bj,s≤1090\le a_i,b_j,s\le10^9.

Examples

Input 1

3 3 1 1
3 2 1
0 3 3

Output 1

3

Explanation

Give the worker of strength 0 a pill, reaching 1 for the third task. The other workers, both of strength 3, take the tasks requiring 3 and 2. All three tasks are completed.

Input 2

2 3 1 5
5 4
0 0 0

Output 2

1

Explanation

All workers start at 0. One pill raises a worker to 5, enough for the first task. The other workers cannot complete either task, so the maximum is one.

Input 3

3 5 3 10
10 15 30
0 10 10 10 10

Output 3

2

Explanation

Give a pill each to the workers of initial strengths 0 and 10. Their resulting strengths, 10 and 20, suffice for the first two tasks. No worker can reach 30 even with a pill, so two is optimal.