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. 标准盒模型、怪异盒模型(box-sizing)

    CSS中Box model是分为两种: W3C标准(标准盒模型) 和 IE标准盒子模型(怪异盒模型).大多数浏览器采用W3C标准模型,而IE中则采用Microsoft自己的标准. 重要的一个属性是bo ...

  2. java中内部类的实例化

  3. ABC155D - Pairs

    本题的模型是典型的求第k小问题,这个问题有2个不一样的点,一是任意选出2个数,不能是同一个,二是这个题有负数,那我们在原有的基础上就需要特判这两点,经典模型是2个数组相乘,此处是1个,那么一样可以枚举 ...

  4. Node.js之EventEmiter

    参考: 1. Node.js之EventEmiter讲解 2. Node.js之events事件 3. 在线运行node.js代码 Node.js主要API使用异步事件驱动模型,异步I/O操作完成时, ...

  5. S7-300 符号IO域的组态 HMI变量指针化的方法以及应用,在一个IO域显示多个温度值的办法

    应用工业场景 例如需要测试很多个节点的温度值的时候,需要监控的位置很多,如果HMI的画面很小, 可以使用符号IO域和变量的间接寻址 符号IO域接近于VB中的combo 控件 实现上图的界面 : 上图界 ...

  6. PAT乙级完结有感

    去年10月开始刷的题,拖拖拉拉的终于借这个假期刷完了,总的来说还是有点小激动的,毕竟,第一次刷完一个体系,在这之前,我在杭电.南阳.洛谷.leetcode.以及我们自己学校的OJ上刷过,但都没有完完整 ...

  7. 第1节 kafka消息队列:7、kafka的消费模型

  8. webpack 4 脚手架搭建

    1.在cmd控制台安装环境  npm install express (这是一个本地服务器配置) 2.在src 文件夹下建 mian.js 和 express.js 两个jS文件

  9. input 数值框处理

    <input type="text"> input  若设置type=“number” ,再想对其调用处理的函数是不起作用的,为此,首先将其设为文本类型 当前要求是数字 ...

  10. ng -----监听变化($scope.$watch())

    需求:项目组件中遇到改变日期触发方法. 困难:日期组件中不涉及释焦功能 解决:在angularjs中用$scope.$watch() 其中name是字符串,是指监听到的具体对象值.