Codeforces Round #404 (Div. 2) B. Anton and Classes 水题
B. Anton and Classes
题目连接:
http://codeforces.com/contest/785/problem/B
Description
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 (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th variant is given by a period of time (l2, i, r2, 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 (l1, r1) and (l2, r2) 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 l1 ≤ i ≤ r1 and l2 ≤ j ≤ r2. 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!
Input
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 l1, i and r1, i (1 ≤ l1, i ≤ r1, 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 l2, i and r2, i (1 ≤ l2, i ≤ r2, i ≤ 109) — the i-th variant of a period of time when Anton can attend programming classes.
Output
Output one integer — the maximal possible distance between time periods.
Sample Input
3
1 5
2 6
2 3
2
2 4
6 8
Sample Output
3
Hint
题意
给你n个区间,再给你m个区间,然后从上面区间选出来一个区间,从下面选出来一个区间。
然后问你在这两个区间选出两个点来,这两个点的最近距离是多少。
题解:
显然最远的就是左边界减去右边界的这种情况。
如果都为负数,那么就说明答案显然为0.
代码
#include<bits/stdc++.h>
using namespace std;
int l1,r1,l2,r2;
int n,m,a,b;
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a>>b;
if(i==0)l1=a,r1=b;
else{
l1=max(a,l1);
r1=min(b,r1);
}
}
cin>>m;
for(int i=0;i<m;i++){
cin>>a>>b;
if(i==0)l2=a,r2=b;
else{
l2=max(a,l2);
r2=min(b,r2);
}
}
cout<<max(0,max(l1-r2,l2-r1))<<endl;
}
Codeforces Round #404 (Div. 2) B. Anton and Classes 水题的更多相关文章
- Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题
A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favo ...
- Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- Codeforces Round #379 (Div. 2) A. Anton and Danik 水题
A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
随机推荐
- MYSQL——root密码更换
方法1: 用SET PASSWORD命令mysql -u rootmysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass') ...
- Git error: hint: Updates were rejected because the remote contains work that you do hint: not have locally
hint: Updates were rejected because the remote contains work that you dohint: not have locally. This ...
- 从简单类型到复杂类型的参数传递用例,以及传递简单string类型的解决办法
一,简单类型的传值 比如 public Users Get(int id) ,它可以使用两种方式获取: api/default/5 $.get("/api/default" ...
- v140平台工具集与v110工具集选择
今天在编译用vs2012编译C++动态库提示:error MSB8020: The builds tools for v140_xp (Platform Toolset = 'v140_xp') ca ...
- HTTP 错误 404.0 - Not Found
当网上的那些修改程序池的方法,无法解决此问题时,可以尝试修改以下的参数: 1.控制面板-->程序-->启用或关闭Windows功能--> Internet Information S ...
- 转:Citrix虚拟化--转自CSDN
http://blog.csdn.net/kkfloat/article/category/1430751/3
- python3之模块urllib
urllib是python内置的HTTP请求库,无需安装即可使用,它包含了4个模块: request:它是最基本的http请求模块,用来模拟发送请求 error:异常处理模块,如果出现错误可以捕获这些 ...
- usb device address error 110
ubuntu失灵了,怎么都起不来,报一堆错误usb device descriptor read/64, error 110......重启,换kvm的接口,usb键盘鼠标...终于在试了下面这个方法 ...
- phantomhs获取网页的高度
function heheda() { window.setTimeout(function () { console.log("---------------------Capture O ...
- python中open函数的用法
用法如下: name = open('errname.txt','w')name.readline()name.close() 1.看下第一行的代码 用来访问磁盘中存放的文件,可以进行读写等操作,例如 ...