CF1148B.Born This Way
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 a1 , a2 , a3 , ..., an and arrive at B ta moments later.
There are m flights from B to C, they depart at time moments b1 , b2 , b3 , ..., bm and arrive at C tb 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 bj≥ai+ta .
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 , ta , tb and k ( 1≤n,m≤2⋅105 , 1≤k≤n+m , 1≤ta,tb≤109 ) — 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 a1 , a2 , a3 , ..., an ( 1≤a1<a2<…<an≤109 ) — the times the flights from A to B depart.
The third line contains m distinct integers in increasing order b1 , b2 , b3 , ..., bm ( 1≤b1<b2<…<bm≤109 ) — 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.