PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000067. Sinh ra đã như vậy (Born This Way)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sinh ra đã như vậy (Born This Way)

Born This Way

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Arkady needs to fly from city AA to city CC via city BB. There are nn flights from AA to BB, departing at strictly increasing times a1<a2<⋯<ana_1<a_2<\cdots<a_n, each taking tat_a units of time. There are mm flights from BB to CC, departing at strictly increasing times b1<b2<⋯<bmb_1<b_2<\cdots<b_m, each taking tbt_b units of time. A connection is possible when the second flight departs no earlier than the first flight's arrival at BB.

Arkady always chooses the remaining itinerary that gets him to CC as early as possible. You may cancel at most kk flights across the two legs to make that earliest arrival as late as possible. Output this worst-case earliest arrival time, or -1 if you can prevent him from reaching CC at all.

Input

The first line contains the five integers n,m,ta,tb,kn,m,t_a,t_b,k.

The second line contains nn strictly increasing departure times a1,…,ana_1,\ldots,a_n.

The third line contains mm strictly increasing departure times b1,…,bmb_1,\ldots,b_m.

Output

Print one integer: the latest possible earliest arrival time at CC after optimal cancellations. Print -1 if no itinerary can remain.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤71\le n,m\le 7; 1≤k≤n+m1\le k\le n+m; 1≤ta,tb≤1091\le t_a,t_b\le 10^9; 1≤a1<⋯<an≤1091\le a_1<\cdots<a_n\le 10^9; 1≤b1<⋯<bm≤1091\le b_1<\cdots<b_m\le 10^9.
  • Subtask 2 (30 points): 1≤n,m≤20001\le n,m\le 2000; 1≤k≤n+m1\le k\le n+m; 1≤ta,tb≤1091\le t_a,t_b\le 10^9; 1≤a1<⋯<an≤1091\le a_1<\cdots<a_n\le 10^9; 1≤b1<⋯<bm≤1091\le b_1<\cdots<b_m\le 10^9.
  • Subtask 3 (50 points): 1≤n,m≤2000001\le n,m\le 200000; 1≤k≤n+m1\le k\le n+m; 1≤ta,tb≤1091\le t_a,t_b\le 10^9; 1≤a1<⋯<an≤1091\le a_1<\cdots<a_n\le 10^9; 1≤b1<⋯<bm≤1091\le b_1<\cdots<b_m\le 10^9.

Examples

Input

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

Output

11

Explanation

Flights from AA depart at 1,3,5,71,3,5,7 and reach BB at 2,4,6,82,4,6,8. Flights from BB depart at 1,2,3,9,101,2,3,9,10 and take one unit of time. Cancel the departure at time 11 on the first leg and the departure at time 99 on the second leg. Arkady takes the flight at 33, reaches BB at 44, then must take the flight at 1010 and arrives at 1111. No choice of two cancellations can force a later earliest arrival.