QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#5378. Matching Problem

Statistics

There are $n$ black points on a number line at coordinates $a[]$, and $n$ white points at coordinates $b[]$ (both 0-indexed). You are also given two parameters $l_a$ and $l_b$, satisfying $n \geq 2$ and $1 \leq l_b < l_a$. Note that multiple points may exist at the same location.

You need to find a permutation $p[]$ of $0$ to $n-1$ such that for all $i$, $a[i] \leq b[p[i]] \leq a[i] + l_a$. You want to maximize the number of indices $i$ such that $b[p[i]] \leq a[i] + l_b$. It is guaranteed that at least one valid permutation exists.

Input

The first line contains three positive integers $n$, $l_a$, and $l_b$.

The next line contains $n$ positive integers representing $a[]$.

The next line contains $n$ positive integers representing $b[]$.

Output

Output a single non-negative integer representing the maximum number of indices that satisfy the condition.

Examples

Input 1

3 5 1
1 2 5
4 6 7

Output 1

1

Note 1

$n=3$, $l_a=5$, $l_b=1$

$a[] = \{1, 2, 5\}$

$b[] = \{4, 6, 7\}$

One optimal permutation is $p[] = \{0, 2, 1\}$. Here, $b[p[2]] = b[1] = 6$ and $a[2] = 5$, so their difference does not exceed $l_b = 1$. No other indices satisfy this condition, so the answer is $1$.

$p[] = \{2, 0, 1\}$ is not a valid permutation because $b[2] = 7$ is matched with $a[0] = 1$, and their difference is $6$, which exceeds $l_a = 5$.

$p[] = \{1, 2, 0\}$ is not a valid permutation because $b[0] = 4$ is matched with $a[2] = 5$, but it does not satisfy $b[0] \geq a[2]$.

$p[] = \{0, 1, 2\}$ is a valid permutation, but the answer is $0$, which is not optimal.

Subtasks

Subtask 1 (4 points): $n \leq 10$.

Subtask 2 (14 points): $n \leq 100$.

Subtask 3 (37 points): $n \leq 5\,000$.

Subtask 4 (16 points): $l_a = 5 \times 10^5$.

Subtask 5 (29 points): No additional constraints.

For all data, $2 \leq n \leq 5 \times 10^5$, $1 \leq a[i], b[i] \leq 5 \times 10^5$, $1 \leq l_b \leq l_a \leq 5 \times 10^5$. It is guaranteed that a valid permutation exists.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.