Avin 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
题意:先是东西方向的车子,然后是南北方向的车子
aa数组里面存放的是东西方向的车,bb数组里面存放的是南北方向的车子,东西方向的车子是不会冲突的,然后就看bb数组里面的数是不是与aa里面的数重复,如果重复的话,就要将bb数组全部向后加上一分钟,重新遍历一遍,如果重新遍历的时候,bb的数字还是与aa相冲突就在加一分钟,在重新遍历
#include<iostream>
#include<cstring>
using namespace std;
int aa[12345];int bb[12345];int vis[123456];
int main()
{
int n,m;
while(cin>>n>>m)
{
int flag=0;
memset(aa,0,sizeof(aa));
memset(bb,0,sizeof(bb));
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
cin>>aa[i];
vis[aa[i]]=1;
}
for(int j=0;j<m;j++) cin>>bb[j];
for(int i=0;i<m;i++)
{
if(vis[flag+bb[i]])
{
flag++;
i=0;
}
}
cout<<flag<<endl;
}
return 0;
}