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 ;
}

最新文章

  1. YYModel 源码解读 总结
  2. struts2中的jsp值传到后台action接收的三种方法
  3. 1.webService入门
  4. 54B
  5. hdoj 2204 Eddy&#39;s爱好
  6. [STL]算法的泛化过程
  7. Web API入门指南(安全)转
  8. webstom 配置git 后左侧菜单栏配色调整
  9. EF初始化mysql数据库codefirst
  10. JNI/NDK开发指南(一)—— JNI开发流程及HelloWorld
  11. C# 的异步
  12. C - Surprising Strings
  13. SpringMVC简单例子
  14. actionInvocation
  15. 第五章SignalR的实时高频通讯
  16. 做web项目时对代码修改后浏览器端不生效的应对方法(持续更新)
  17. javascript面向对象编程笔记
  18. SQL ALTER TABLE 语句
  19. 使用mybatis plus 操作数据库
  20. Java:ConcurrentHashMap

热门文章

  1. keil中的一些技巧
  2. windows下安装subversion
  3. 什么是Nib文件
  4. iOS学习7:iOS沙盒(sandBox)机制(一)之获取沙盒路径及目录说明(转)
  5. jsoup教学系列
  6. ‘A’ = N’A’ , will not kill index seek in sqlserver version above 2014 anymore
  7. 单元测试报错:unable to find a @SpringBootConfiguration
  8. Python 基础之推导式
  9. requests---requests封装请求类型
  10. 初始化加载和导航时脚本执行的函数(初始化脚本执行环境)page.evaluateOnNewDocument