A10960 | Anton and Classes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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!
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!
输入格式
The first line of the input contains a single integer $n$ $(1<=n<=200000)$ — 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}<=10^{9})$ — 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<=200000)$ — 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}<=10^{9})$ — the $i$ -th variant of a period of time when Anton can attend programming 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}<=10^{9})$ — 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<=200000)$ — 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}<=10^{9})$ — the $i$ -th variant of a period of time when Anton can attend programming classes.
输出格式
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$ .
In the second sample if he chooses any pair of periods, they will intersect. So the answer is $0$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted