Logo
(追記) (追記ここまで)

18530번 - ICPC Camp 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 512 MB90494054.054%

문제

John is a leading organizer of this year’s North America ICPC training camp. The camp lasts several days. On each day, there will be a lecture introducing two problems: one classical problem and one creative problem. Each problem can only be introduced once during the entire camp. Every problem has an integer difficulty level.

John knows that the lecture on each day should not be too overwhelming. Therefore, the sum of the difficulties of the two problems in a single day shall not exceed some fixed value. Also, the two problems on each day should be roughly on the same level. Let d be the absolute difference between the difficulties of the two problems introduced on any given day. The maximum of all of the ds, defined as D, should be as small as possible.

If John chooses problems well and arranges them wisely, what is the smallest D he can achieve for the n days of the ICPC training camp?

입력

The first line of input contains four space-separated integers n, p, q (1 ≤ n, p, q ≤ 2 · 105, n ≤ min(p, q)) and s (0 ≤ s ≤ 109), where n is the number of days of the camp, p is the number of classical problems, q is the number of creative problems, and s is the maximum sum of difficulties on any given day.

Each of the next p lines contains an integer x (0 ≤ x ≤ 109). These are difficulties of the p classical problems.

Each of the next q lines contains an integer y (0 ≤ y ≤ 109). These are difficulties of the q creative problems.

출력

Output a single integer, which is the smallest D John can achieve, or −1 if there is no way John can select problems for the n training days.

제한

예제 입력 1

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

예제 출력 1

4

예제 입력 2

4 4 4 15
1
5
10
12
1
3
10
14

예제 출력 2

13

예제 입력 3

4 4 4 10
1
12
5
10
1
10
3
14

예제 출력 3

-1

힌트

출처

ICPC > Regionals > North America > North America Championship > North America Championship 2020 G번

Contest > Open Cup > 2019/2020 Season > Stage 13: Grand Prix of America G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /