#TP0000020. Phân căn hộ (Apartments)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phân căn hộ (Apartments)
Apartments
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
There are applicants looking for apartments and available apartments. Applicant wants an apartment of size and accepts a difference of at most from that size. Apartment has size .
Each apartment can be assigned to at most one applicant, and each applicant may receive at most one apartment. An assignment is valid if . Find the maximum number of applicants who can receive apartments.
Input
- The first line contains three integers : the numbers of applicants and apartments, and the maximum allowed size difference.
- The second line contains integers , the desired apartment sizes.
- The third line contains integers , the available apartment sizes.
Output
Print one integer: the maximum number of applicants who can receive an apartment.
Subtasks
- Subtask 1 (20 points): ; ; for every element.
- Subtask 2 (30 points): ; ; for every element.
- Subtask 3 (50 points): ; ; for every element.
Examples
Input
4 3 5
60 45 80 60
30 60 75
Output
2
Explanation
An apartment of size can be assigned to one applicant requesting , and the apartment of size to the applicant requesting , since . The apartment of size cannot serve the applicant requesting because their difference is . At most two apartments can be assigned validly, so the answer is .