QOJ.ac

QOJ

時間限制: 5 s 記憶體限制: 512 MB 總分: 100

#3167. ICPC 训练营

统计

John 是今年北美 ICPC 训练营的主要组织者。训练营持续数天。每天都会有一场讲座,介绍两个问题:一个经典问题和一个创意问题。每个问题在整个训练营期间只能被介绍一次。每个问题都有一个整数难度值。

John 知道每天的讲座内容不应过于繁重。因此,每天两个问题的难度之和不得超过某个固定值 $s$。此外,每天的两个问题难度应大致相当。设 $d$ 为当天介绍的两个问题难度之间的绝对差值。定义 $D$ 为所有 $d$ 中的最大值,John 希望 $D$ 尽可能小。

如果 John 能妥善选择并合理安排问题,那么在 $n$ 天的 ICPC 训练营中,他能实现的最小 $D$ 是多少?

输入格式

输入的第一行包含四个空格分隔的整数 $n, p, q$ ($1 \le n, p, q \le 2 \cdot 10^5, n \le \min(p, q)$) 和 $s$ ($0 \le s \le 10^9$),其中 $n$ 是训练营的天数,$p$ 是经典问题的数量,$q$ 是创意问题的数量,$s$ 是每天允许的最大难度之和。

接下来的 $p$ 行,每行包含一个整数 $x$ ($0 \le x \le 10^9$),表示 $p$ 个经典问题的难度。

接下来的 $q$ 行,每行包含一个整数 $y$ ($0 \le y \le 10^9$),表示 $q$ 个创意问题的难度。

输出格式

输出一个整数,表示 John 能实现的最小 $D$;如果 John 无法为 $n$ 天的训练选择合适的问题,则输出 $-1$。

样例

样例输入 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

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.