PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000028. Ghép cặp khiêu vũ (BerSU Ball)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ghép cặp khiêu vũ (BerSU Ball)
BerSU Ball
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are boys and girls with integer skill levels. A pair is valid if their skill difference is at most . Each person may belong to at most one pair. Find the maximum number of pairs.
Input
The first line contains , the second the boys' skills; the third contains , the fourth the girls' skills.
Output
Print the maximum number of pairs.
Constraints
- .
- for , .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): Full constraints.
Examples
Input
4
1 4 6 2
5
5 1 5 7 9
Output
3
Explanation
The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.