CF785B.Anton and Classes
普及-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (_l_1, i, _r_1, i). Also he has m variants when he will attend programming classes, i-th variant is given by a period of time (_l_2, i, _r_2, i).
Anton needs to choose exactly one of n possible periods of time when he will attend chess classes and exactly one of m possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal.
The distance between periods (_l_1, _r_1) and (_l_2, _r_2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible |i - j|, where _l_1 ≤ i ≤ _r_1 and _l_2 ≤ j ≤ _r_2. In particular, when the periods intersect, the distance between them is 0.
Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number!
安东喜欢下棋,也喜欢编程。毫不奇怪,他决定去上国际象棋课和编程课。
安东有 n 种可选的国际象棋课时间安排,其中第 i 种由一个时间段 (l1,i, r1,i) 给出;同时,他还有 m 种可选的编程课时间安排,其中第 i 种由一个时间段 (l2,i, r2,i) 给出。
安东必须从 n 个可能的国际象棋课时间段中恰好选择一个,并从 m 个可能的编程课时间段中恰好选择一个。他希望两节课之间有休息时间,因此在所有可能的时间段组合中,他想选择两个时间段之间距离最大的一组。
时间段 (l1, r1) 与 (l2, r2) 之间的距离定义为:第一个时间段内某点与第二个时间段内某点之间的最小可能距离,即 min∣i−j∣,其中 l1≤i≤r1 且 l2≤j≤r2。特别地,当两个时间段存在交集(即重叠或相邻)时,它们之间的距离为 0。
安东想知道:在最优选择下,他两节课之间的休息时间最长能有多长?请帮助安东求出这个数值!
输入格式
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of time periods when Anton can attend chess classes.
Each of the following n lines of the input contains two integers _l_1, i and _r_1, i (1 ≤ _l_1, i ≤ _r_1, i ≤ 109) — the i-th variant of a period of time when Anton can attend chess classes.
The following line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of time periods when Anton can attend programming classes.
Each of the following m lines of the input contains two integers _l_2, i and _r_2, i (1 ≤ _l_2, i ≤ _r_2, i ≤ 109) — the i-th variant of a period of time when Anton can attend programming classes.
输入的第一行包含一个整数 n(1≤n≤200000)—— 表示 Anton 可以参加国际象棋课程的时间段数量。
接下来的 n 行,每行包含两个整数 l1,i 和 r1,i(1≤l1,i≤r1,i≤109)—— 表示第 i 个 Anton 可以参加国际象棋课程的时间区间。
接下来的一行包含一个整数 m(1≤m≤200000)—— 表示 Anton 可以参加编程课程的时间段数量。
接下来的 m 行,每行包含两个整数 l2,i 和 r2,i(1≤l2,i≤r2,i≤109)—— 表示第 i 个 Anton 可以参加编程课程的时间区间。
输出格式
Output one integer — the maximal possible distance between time periods.
输出一个整数——时间区间之间的最大可能距离。
输入输出样例
输入#1
3 1 5 2 6 2 3 2 2 4 6 8
输出#1
3
输入#2
3 1 5 2 6 3 7 2 2 4 1 4
输出#2
0
说明/提示
In the first sample Anton can attend chess classes in the period (2, 3) and attend programming classes in the period (6, 8). It's not hard to see that in this case the distance between the periods will be equal to 3.
In the second sample if he chooses any pair of periods, they will intersect. So the answer is 0.
在第一个样例中,安东可以在时间段 (2, 3) 参加国际象棋课程,并在时间段 (6, 8) 参加编程课程。不难看出,此时两个时间段之间的距离等于 3。
在第二个样例中,无论他选择哪一对时间段,它们都会相交。因此答案为 0。
输入解题思路,AI测评打分。不知道怎么写?