#BS0000323. Phân công nhiều việc nhất (Maximum Number of Tasks You Can Assign)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 tasks and workers. Task requires strength at least ; worker initially has strength .
You may distribute up to pills. Each pill adds 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 : the number of tasks, workers, pills, and the strength increase per pill.
- The second line contains integers , the task requirements.
- The third line contains integers , the initial worker strengths.
Output
Print one integer: the maximum number of completed tasks.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
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.