vin is observing the cars at a crossroads. He finds that there are n cars running in the east-west direction with the i-th car passing the intersection at time ai . There are another m cars running in the north-south direction with the i-th car passing the intersection at time bi . If two cars passing the intersections at the same time, a traffic crash occurs. In order to achieve world peace and harmony, all the cars running in the north-south direction wait the same amount of integral time so that no two cars bump. You are asked the minimum waiting time.

input

The first line contains two integers n and m (1 ≤ n, m ≤ 1, 000). The second line contains n distinct integers ai (1 ≤ ai ≤ 1, 000). The third line contains m distinct integers bi (1 ≤ bi ≤ 1, 000).

output

Print a non-negative integer denoting the minimum waiting time.

Sample Input

1 1
1
1
1 2
2
1 3 Sample Output
1
0 题意:n辆车从一边经过十字路口,m辆车从另一边经过十字路口,当n方向的车经过路口时,m方向的车必须停下等待。给定车辆经过路口的时间,问m方向的车最少要等多久 题解:假设等待时间时t,当两个方向 的车同时经过路口时需要等,即b[j]+t==a[i],枚举输出最大的t即可
#include<iostream>
#include<string.h>
using namespace std;
int a[],b[];
int main()
{
int n,m,x;
while(cin>>n>>m)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int i=;i<n;i++)
{
cin>>x;
a[x]=;
}
for(int i=;i<m;i++)
cin>>b[i];
int t=;
for(int i=;i<m;i++)
{
if(a[b[i]+t])//如果b[i]+t==a[j]
{
t++;
i=-;
}
}
cout<<t<<endl;
}
return ;
}

G - Traffic的更多相关文章

  1. zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)

    题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...

  2. CCPC2019江西省赛-Problem G.Traffic

    题目描述: /*纯手打题面*/ Avin is observing the cars at a crossroads.He finds that there are n cars running in ...

  3. 152 - - G Traffic Light 搜索(The 18th Zhejiang University Programming Contest Sponsored by TuSimple )

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5738 题意 给你一个map 每个格子里有一个红绿灯,用0,1表示 ...

  4. Complexity and Tractability (3.44) - The Traveling Salesman Problem

    Copied From:http://csfieldguide.org.nz/en/curriculum-guides/ncea/level-3/complexity-tractability-TSP ...

  5. Reading SBAR SDN flow-Based monitoring and Application Recognition

    概要 在sdn下,控制平面基于网络测量的的数据控制网络,而细粒度的管理得益于细粒度的测量数据.针对sdn环境下的细粒度测量(识别具体应用程序),可以实现对细粒度的流量管控. 设计了识别系统SBAR,对 ...

  6. QDU_组队训练(AJFC)

    A - Pretty Matrix DreamGrid's birthday is coming. As his best friend, BaoBao is going to prepare a g ...

  7. <JAVA图像学习笔记>十字路口交通模拟--操作系统模拟课后小项目

    项目的要求很简单: 模拟出十字路口的交通控制情况: 秒. 当东西(或南北)方向红灯时,所有车辆(除了消防车.救护车.警车)均排队等待,当东西(或南北)方向绿灯时,所有车辆按序行驶(不准超车). 制作这 ...

  8. Smart internet of things services

    A method and apparatus enable Internet of Things (IoT) services based on a SMART IoT architecture by ...

  9. Network management system scheduling for low power and lossy networks

    In one embodiment, a network management system (NMS) determines an intent to initialize a request-re ...

随机推荐

  1. Windows驱动开发-IRP超时处理

    IRP被送到底层驱动程序以后,由于硬件设备的问题,IRP不能得到及时处理,甚至有可能永远不会被处理,这时候需要对IRP超时情况进行处理,一旦在规定时间内,IRP没有被处理,操作系统就会进入到IRP的处 ...

  2. 【PAT甲级】1016 Phone Bills (25 分)(结构体排序)

    题意: 输入24个正整数代表从0到23每个小时通话一分钟花费的美分.输入一个正整数N(<=1000),然后输入N组字符串,每个字符串包含客户的名字和通话的时刻以及打出或者挂断的状态. 按照字典序 ...

  3. H.264 中的Annex B格式和AVCC格式

    首先要理解的是没有标准的H.264基本流格式.文档中的确包含了一个Annex,特别是描述了一种可能的格式Annex B格式,但是这个并不是一个必须要求的格式.标准文档中指定了视频怎样编码成独立的包,但 ...

  4. Servlet简单的登陆窗口

    web.xml配置: jsp代码: 注意:action书写的是为这次登陆做处理类的别名,method就是请求的方式 Get请求方式没有请求实体 //如果只是看效果就光写一下service方法就行了 p ...

  5. 设计模式课程 设计模式精讲 16-4 代理模式Coding-动态代理

    1 代码演练 1.1 动态代理 2 疑难解答 2.1 动态代理invoke怎么执行的? 2.2 感觉这块理解的不是很好,下边有时间再看看 1 代码演练 1.1 动态代理 重点: 重点关注动态代理类 测 ...

  6. egret inspector插件无法使用

    调试项目要安装egret inspector查看游戏场景的资源,装了插件点击不显示. 解决方法:将chrome版本回退. 下载地址:http://mydown.yesky.com/pcsoft/279 ...

  7. HTML<head></head>中标签的含义

    我们都知道,HTML的标签可以分为很多种,head 里面的我们称为元信息类标签,诸如title.meta.style.link.base.script这些,他们用来描述文档的一些基本信息. 1. ti ...

  8. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:清除浮动

    <!DOCTYPE html> <html> <head> <title>Bootstrap .clearfix 实例</title> &l ...

  9. css实现单行居中,两行居左

    居中需要用到 text-align:center,居左是默认值也就是text-align:left.要让两者结合起来需要多一个标签. <h2><p>单行居中,多行居左</ ...

  10. 【剑指Offer面试编程题】题目1387:斐波那契数列--九度OJ

    题目描述: 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.斐波那契数列的定义如下: 输入: 输入可能包含多个测试样例,对于每个测试案例, 输入包括一个整数n(1< ...