Born This Way

题意翻译

## 题目描述 $Arkady$ 买了一张从 $A$ 市到 $C$ 市的机票。不幸的是,这两个城市之间没有直飞航班,但是从 $A$ 市到 $B$ 市和从 $B$ 市到 $C$ 市的航班有很多。 从 $A$ 市到 $B$ 市有 $N$ 个航班,它们分别在 $a_1,a_2,a_3,...$ $,a_n$ 时起飞,在 $ta$ 个单位时间的飞行后到达 $B$ 市。 从 $B$ 市到 $C$市 有 $M$ 个航班,它们在 $b_1,b_2,b_3,...$ $,b_m$ 起飞。在 $tb$ 个单位时间的飞行后到达 $C$ 市。 转机的时间忽略不计,因此只有当 $b_j \ge a_i+ta$ 时,$Arkady$ 才能搭乘从 $A$ 市到 $B$ 市的第 $i$ 次航班和 $B$ 市到 $C$ 市的第 $j$ 次航班抵达目的地。 你最多可以不择手段地取消 $k$ 次航班。如果你取消了航班,$Arkady$ 当然就不能搭乘它了。 $Arkady$ 想尽早到 $C$ 市,而你想让他尽可能地晚到 $C$ 市。计算你取消了 $k$ 次航班之后 $Arkady$ 最早到达 $C$ 市的时间点。如果你可以通过取消 $k$ 次或更少的航班,使 $Arkady$ 不能达到 $C$ 市,请输出 $−1$ 。 ## 输入输出格式 ### 输入格式 输入的第一行包括五个整数 $n,m,ta,tb$ 和 $k$ ($1 \le n \le 2\cdot 10^5$ , $1 \le ta, tb \le 10^9 $ , $1 \le ta, tb \le 10^9$)。即从 $A$ 市到 $B$ 市的航班数,从 $B$ 市到 $C$ 市的航班数,从$A$ 市到 $B$ 市的飞行用时,从 $B$ 市到 $C$ 市的飞行用时和你可以取消的航班数量。 第二行有 $n$ 个递增的整数 $a_1,a_2,a_3,...$ $,a_n$ ($1 \le a_1<a_2<\ldots<a_n \le 10^9 $)—— 从 $A$ 到 $B$ 的航班起飞的时间 。 第三行有 $m$ 个递增的整数 $b_1,b_2,b_3,...$ $,b_n$ ($1 \le b_1<b_2<\ldots<b_n \le 10^9 $)—— 从 $B$ 到 $C$ 的航班起飞的时间 。 ### 输出格式: 如果您可以取消 $k$ 或更少次数的航班,使 $Arkady$ 根本不可能达到 $C$ 市,请输出−1。 否则,如果您取消k次航班,只能最大限度地延后这一时间,则输出 $Arkady$ 到达 $C$ 市的最晚的最早抵达时间 。

题目描述

Arkady bought an air ticket from a city A to a city C. Unfortunately, there are no direct flights, but there are a lot of flights from A to a city B, and from B to C. There are $ n $ flights from A to B, they depart at time moments $ a_1 $ , $ a_2 $ , $ a_3 $ , ..., $ a_n $ and arrive at B $ t_a $ moments later. There are $ m $ flights from B to C, they depart at time moments $ b_1 $ , $ b_2 $ , $ b_3 $ , ..., $ b_m $ and arrive at C $ t_b $ moments later. The connection time is negligible, so one can use the $ i $ -th flight from A to B and the $ j $ -th flight from B to C if and only if $ b_j \ge a_i + t_a $ . You can cancel at most $ k $ flights. If you cancel a flight, Arkady can not use it. Arkady wants to be in C as early as possible, while you want him to be in C as late as possible. Find the earliest time Arkady can arrive at C, if you optimally cancel $ k $ flights. If you can cancel $ k $ or less flights in such a way that it is not possible to reach C at all, print $ -1 $ .

输入输出格式

输入格式


The first line contains five integers $ n $ , $ m $ , $ t_a $ , $ t_b $ and $ k $ ( $ 1 \le n, m \le 2 \cdot 10^5 $ , $ 1 \le k \le n + m $ , $ 1 \le t_a, t_b \le 10^9 $ ) — the number of flights from A to B, the number of flights from B to C, the flight time from A to B, the flight time from B to C and the number of flights you can cancel, respectively. The second line contains $ n $ distinct integers in increasing order $ a_1 $ , $ a_2 $ , $ a_3 $ , ..., $ a_n $ ( $ 1 \le a_1 < a_2 < \ldots < a_n \le 10^9 $ ) — the times the flights from A to B depart. The third line contains $ m $ distinct integers in increasing order $ b_1 $ , $ b_2 $ , $ b_3 $ , ..., $ b_m $ ( $ 1 \le b_1 < b_2 < \ldots < b_m \le 10^9 $ ) — the times the flights from B to C depart.

输出格式


If you can cancel $ k $ or less flights in such a way that it is not possible to reach C at all, print $ -1 $ . Otherwise print the earliest time Arkady can arrive at C if you cancel $ k $ flights in such a way that maximizes this time.

输入输出样例

输入样例 #1

4 5 1 1 2
1 3 5 7
1 2 3 9 10

输出样例 #1

11

输入样例 #2

2 2 4 4 2
1 10
10 20

输出样例 #2

-1

输入样例 #3

4 3 2 3 1
1 999999998 999999999 1000000000
3 4 1000000000

输出样例 #3

1000000003

说明

Consider the first example. The flights from A to B depart at time moments $ 1 $ , $ 3 $ , $ 5 $ , and $ 7 $ and arrive at B at time moments $ 2 $ , $ 4 $ , $ 6 $ , $ 8 $ , respectively. The flights from B to C depart at time moments $ 1 $ , $ 2 $ , $ 3 $ , $ 9 $ , and $ 10 $ and arrive at C at time moments $ 2 $ , $ 3 $ , $ 4 $ , $ 10 $ , $ 11 $ , respectively. You can cancel at most two flights. The optimal solution is to cancel the first flight from A to B and the fourth flight from B to C. This way Arkady has to take the second flight from A to B, arrive at B at time moment $ 4 $ , and take the last flight from B to C arriving at C at time moment $ 11 $ . In the second example you can simply cancel all flights from A to B and you're done. In the third example you can cancel only one flight, and the optimal solution is to cancel the first flight from A to B. Note that there is still just enough time to catch the last flight from B to C.