QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#15886. Set

统计

Huaji-chan has two sets $A$ and $B$ of sizes $n$ and $m$ respectively. Their elements are integers in $[0, L]$, and both $0$ and $L$ are included in both sets. She wants to find a minimum set $C$ such that:

  • $0, L \in C$.
  • After sorting the elements of $A \cap C$ in ascending order, the difference between any two adjacent elements does not exceed $a$.
  • After sorting the elements of $B \cap C$ in ascending order, the difference between any two adjacent elements does not exceed $b$.

However, Huaji-chan is too clumsy to calculate this. Please help poor Huaji-chan. To avoid causing you extra trouble, you only need to tell her the size of $C$. Specifically, if no such set $C$ exists, output $-1$.

Input

The input is read from standard input.

The first line contains five positive integers $n, m, L, a, b$ ($2 \le n, m \le 10^6$, $1 \le a, b \le L \le 10^{18}$).

The second line contains $n$ distinct natural numbers in ascending order, representing the elements of set $A$. It is guaranteed that the first number is $0$ and the last number is $L$.

The third line contains $m$ distinct natural numbers in ascending order, representing the elements of set $B$. It is guaranteed that the first number is $0$ and the last number is $L$.

Output

Output to standard output.

Output a single positive integer representing the size of the required set $C$. Specifically, if no such set $C$ exists, output $-1$.

Examples

Input 1

10 10 30 8 6
0 2 5 8 11 18 20 21 23 30
0 1 6 12 14 18 21 24 28 30

Output 1

9

Note 1

One minimal set $C$ is $\{0, 6, 8, 11, 12, 18, 23, 24, 30\}$, so the answer is $9$.

Input 2

3 4 10 6 4
0 6 10
0 2 7 10

Output 2

-1

Input 3

See 3.in and 3.ans in the problem directory.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#391EditorialOpenTHUPC2026初赛 K 题 的一种[maybe linear]做法incent2025-12-16 17:24:32View

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.