Traffic

题解:错的主要原因我把题意理解错了。。。。应该是先判断是否存在碰撞,不能走着判断这,那样不行。

Problem Description

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

 

 

Source

2019CCPC-江西省赛(重现赛)- 感谢南昌大学

#include
#include
#include
using namespace std;
int a[1010];
int b[1010];
int c[2020];
int main()
{
	int n,m;
	memset(c,0,sizeof(c));
	scanf("%d%d",&n,&m);
	for(int i=0;i=0;i--)
 		{
 			if(c[i])
 			{
 				c[i]=0;
 				c[i+1]=1;
			 }
		 }
	 }
	printf("%d\n",num);
	return 0;
}

 

你可能感兴趣的:(思维)