Anton 上课题

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.

Examples:

Input:
3
1 5
2 6
2 3
2
2 4
6 8
Output
3
Input:
3
1 5
2 6
3 7
2
2 4
1 4
Output
0

Note

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.

题目大意:Anton要去上两个课程,但是每个课程都有多种选择,问你哪种选择可以使Anton的休息时间更长,并求出休息时间,假如所有的课程都出现了时间重叠,那么输出答案-1。
解题思路:我们只需要找出第一个课程的最早结束时间和第二个课程的最晚结束时间然后相减就得出了答案,因为我们并不知道先上哪个课程最好,所以我们把两种情况都算出来然后比较最优解就行了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue> using namespace std;
const int MAX=;
int n,m; struct De
{
int a,b;
};
De xang[MAX],bian[MAX]; bool cmp(De x,De y)
{
return x.b>y.b;
} bool cep(De x,De y)
{
return x.a>y.a;
} int main()
{
scanf("%d",&n);
int ans1,ans2;
for(int i=;i<n;i++)
scanf("%d %d",&xang[i].a,&xang[i].b);
scanf("%d",&m);
for(int i=;i<m;i++)
scanf("%d %d",&bian[i].a,&bian[i].b);
sort(xang,xang+n,cmp);
sort(bian,bian+m,cep);
ans1=bian[].a-xang[n-].b;
sort(xang,xang+n,cep);
sort(bian,bian+m,cmp);
ans2=xang[].a-bian[m-].b;
if(ans1<=&&ans2<=) printf("0\n");
else printf("%d\n",ans1>ans2?ans1:ans2);
return ;
}

 

Anton 上课题的更多相关文章

  1. 【腾讯Bugly干货分享】OCS——史上最疯狂的iOS动态化方案

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/zctwM2Wf8c6_sxT_0yZvXg 导语 在 ...

  2. 年终巨献 史上最全 ——LINQ to SQL语句

    LINQ to SQL语句(1)之Where 适用场景:实现过滤,查询等功能. 说明:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的,而判断条件就是它后面所接的子句.Where操 ...

  3. JVM 平台上的各种语言的开发指南

    JVM 平台上的各种语言的开发指南 为什么我们需要如此多的JVM语言? 在2013年你可以有50中JVM语言的选择来用于你的下一个项目.尽管你可以说出一大打的名字,你会准备为你的下一个项目选择一种新的 ...

  4. 写在MongoCola在Github上获得200个Star之后

    MongoCola MongoCola是一个开源的MongoDB管理工具. 由于最初版本的设计失误,所以现在只能在Windows上使用,虽然可以在OSX上使用,但是非常别扭. 契机 MongoCola ...

  5. DB层面上的设计 分库分表 读写分离 集群化 负载均衡

    第1章  引言 随着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大型的 互联网应用,每天几十亿的PV无疑对数据库造成了相当高的负载.对于系统的稳定性和扩展性造成了极大的 ...

  6. 对话机器学习大神Yoshua Bengio(上)

    Yoshua Bengio教授(个人主页)是机器学习大神之一,尤其是在深度学习这个领域.他连同Geoff Hinton老先生以及 Yann LeCun(燕乐存)教授,缔造了2006年开始的深度学习复兴 ...

  7. Spark Streaming揭秘 Day20 动态Batch size实现初探(上)

    Spark Streaming揭秘 Day20 动态Batch size实现初探(上) 今天开始,主要是通过对动态Batch size调整的论文的解析,来进一步了解SparkStreaming的处理机 ...

  8. SaaS系列介绍之六: SaaS模式分析(上)

    1 引言 如果我们想要更多的玫瑰花,就必须种植更多的玫瑰树.                            ________姚群<成功激励格言精选> SaaS模式是个新兴的话题,有 ...

  9. 在MVC中利用uploadify插件实现上传文件的功能

    趁着近段的空闲时间,开发任务不是很重,就一直想把以前在仓促时间里所写的多文件上传功能改一下,在网上找了很多例子,觉得uploadify还可以,就想用它来试试.实现自己想要的功能.根据官网的开发文档,同 ...

随机推荐

  1. 【产品设计】【转】APP界面设计规范编写指南(人人都是产品经理)

    转自 :http://www.woshipm.com/ucd/608557.html 作者:EID_UX_DESIGN,微信公众号:EID_center 原文地址:http://www.ui.cn/d ...

  2. 【Linux】【Jenkins】配置过程中,立即构建时,maven找不到的问题解决方案

    在Linux环境下配置Jenkins执行时,发现不能执行Maven,这个比较搞了. A Maven installation needs to be available for this projec ...

  3. Android 开发 框架系列 Google的ORM框架 Room

    目录 简介 导入工程 使用流程概况 一个简单的小Demo 深入学习 @Entity使用 自定义表名 tableName  自定义字段名@ColumnInfo 主键 @PrimaryKey 索引 @In ...

  4. Java 身份证判断性别获取年龄

    import com.alibaba.fastjson.JSON; import org.junit.Test; import java.text.SimpleDateFormat; import j ...

  5. Webform(条件查询)

    <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...

  6. django admin 设置(转载https://www.cnblogs.com/wumingxiaoyao/p/6928297.html)

    Django admin 一些有用的设置   Django自带的后台管理是Django明显特色之一,可以让我们快速便捷管理数据.后台管理可以在各个app的admin.py文件中进行控制.以下是我最近摸 ...

  7. tkinter窗口居中方法

    tkinter窗口居中 from tkinter import * class MyFrm(Frame): def __init__(self, master): self.root=master s ...

  8. cdnbest里站点域名不同步到节点,报400错误的一般原因

    报400错误一般是站点里的域名没有同步到节点上面的原因,产生的原因一般是下面两点原因: 1.检查节点列表如下图所示的状态是否打钩,这是节点和主控的通信状态,打叉表示连接有问题 这里打叉的几种原因(1) ...

  9. openvpn显示连接成功但是无法进行git操作

    使用openvpn连接公司内网以进行git操作.以管理员身份运行openvpn gui,一段时间后提示连接成功,右下角图标变成绿色,但是进行git操作,每次都发生失败,提示连接不上.右键点击openv ...

  10. Python设计模式 - UML - 类图(Class Diagram)

    简介 类图是面向对象分析和设计的核心,用来描述系统各个模块中类与类之间.接口与接口之间.类与接口之间的关系,以及每个类的属性.操作等特性,一般在详细设计过程中实施. 类图本身就是现实世界的抽象,是对系 ...