Problem:


Problem A: Traffic Analysis

There are two cameras which observe the up line and the down line respectively on the double lane (please see the following figure). These cameras are located on a line perpendicular to the lane, and we call the line 'monitoring line.' (the red line in the figure)

Monitoring systems are connected to the cameras respectively.
When a car passes through the monitoring line, the corresponding monitoring system records elapsed time (sec) from the start of monitoring.

Your task is to write a program which reads records of the two monitoring systems and prints the maximum time interval where cars did not pass through the monitoring line.

The two monitoring system start monitoring simultaneously. The end of monitoring is indicated by the latest time in the records.

Input

The input consists of multiple datasets. Each dataset consists of:

n m
tl1 tl2 ... tln
tr1 tr2 ... trm

n, m are integers which represent the number of cars passed through monitoring line on the up line and the down line respectively. tli, tri are integers which denote the elapsed time when i-th car passed through the monitoring line for the up line and the down line respectively. You can assume that tl1 < tl2 < ... < tln、 tr1 < tr2 < ... < trm.

You can also assume that n, m ≤ 10000, and 1 ≤ tli, tri ≤ 1,000,000.

The end of input is indicated by a line including two zero.

Output

For each dataset, print the maximum value in a line.

Sample Input

4 5
20 35 60 70
15 30 40 80 90
3 2
10 20 30
42 60
0 1
100
1 1
10
50
0 0

Output for the Sample Input

20
18
100
40



Sample input:
4 5
20 35 60 70
15 30 40 80 90
3 2
10 20 30
42 60
0 1
100
1 1
10
50
0 0


Sample output:
20
18
100
40

Submission status: Wrong Answer

Solution code:
while True:
	n,m = map(int,raw_input().split())
	if n == 0 and m == 0 : break

	traffic = []
	if n != 0:
		traffic = map(int,raw_input().split())
	if m != 0:
		traffic += map(int,raw_input().split())
	
	traffic.sort()
	
	max = 0
	next = traffic[0]
	if n + m == 1:
		max = traffic[0]
	else:
		for var in traffic[1:]:
			if var - next > max:
				max = var - next
			next = var
		
	print max

Submission status: Wrong Answer

Solution code:
get = lambda:map(int, raw_input().split())
while 1:
    n,m = get()
    if n==m==0: break
    t = []
    if n!=0: t += get()
    if m!=0: t += get()
    t.sort()
    print max(t[i+1]-t[i] for i in xrange(n+m-1)) if n+m>1 else t[0]

Submission status: Wrong Answer

Solution code:
get = lambda:map(int, raw_input().split())
while 1:
    n,m = get()
    if n==m==0: break
    t = [0]
    if n!=0: t += get()
    if m!=0: t += get()
    t.sort()
    print max(t[i+1]-t[i] for i in xrange(n+m-1)) if n+m>1 else t[0]

Submission status: Wrong Answer

Solution code:
get = lambda:map(int, raw_input().split())
while 1:
    n,m = get()
    if n==m==0: break
    t = [0]
    if n!=0: t += get()
    if m!=0: t += get()
    t.sort()
    print t
    print max(t[i+1]-t[i] for i in xrange(n+m)) if n+m>1 else t[0]

Submission status: Wrong Answer

Solution code:
get = lambda:map(int, raw_input().split())
while 1:
    n,m = get()
    if n==m==0: break
    t = [0]
    if n!=0: t += get()
    if m!=0: t += get()
    t.sort()
    print max(t[i+1]-t[i] for i in xrange(n+m)) if n+m>1 else t[0]

Submission status: Wrong Answer

Solution code:
while 1:
	r,l = map(int,raw_input().split())
	if (r,l) == (0,0): break
	rcar,lcar = [],[]
	if r > 0: rcar = map(int,raw_input().split())
	if l > 0: lcar = map(int,raw_input().split())
	car = sorted(rcar + lcar)
	if r+l>1: car = [car[i+1] - car[i] for i in range(r+l-1)]
	print max(car)

Submission status: Accepted

Solution code:
# AOJ 1029: Traffic Analysis
# Python3 2018.7.6 bal4u

import sys
from sys import stdin
input = stdin.readline

while True:
	n, m = map(int, input().split())
	if n == 0 and m == 0: break
	if n > 0: a = list(map(int, input().split()))
	if m > 0: b = list(map(int, input().split()))
	ans = i = j = 0
	s, t = 0, -1
	while i < n or j < m:
		if i < n:
			if s == a[i]: i += 1
			if i < n: t = a[i]
		if j < m:
			if s == b[j]: j += 1
			if j < m and (t < 0 or b[j] < t): t = b[j]
		if t >= 0:
			if i < n and t == a[i]: i += 1
			if j < m and t == b[j]: j += 1
			ans = max(ans, t-s)
			s, t = t, -1
	if t >= 0: ans = max(ans, t-s)
	print(ans)

Submission status: Accepted

Solution code:
while True:
	n,m = map(int,raw_input().split())
	if n == 0 and m == 0 : break

	traffic = [0]
	if n != 0:
		traffic = map(int,raw_input().split())
	if m != 0:
		traffic += map(int,raw_input().split())
	
	traffic.sort()
	
	max = traffic[0]
	next = traffic[0]
	for var in traffic[1:]:
		if var - next > max:
			max = var - next
		next = var
		
	print max

Submission status: Accepted

Solution code:
while 1:
    t,(n,m)=[0],map(int,input().split())
    if n==m==0:break
    if n:t+=map(int,input().split())
    if m:t+=map(int,input().split())
    t.sort()
    print(max(t[i+1]-t[i] for i in range(n+m)))

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,raw_input().split())
    if n==m==0:break
    up=map(int,raw_input().split()) if n!=0 else []
    down=map(int,raw_input().split()) if m!=0 else []
    upDown=up+down
    upDown.sort()
    maxlen=upDown[0]
    for i in range(n+m-1):
        maxlen=max(maxlen,upDown[i+1]-upDown[i])
    print maxlen

Submission status: Accepted

Solution code:
get = lambda:map(int, raw_input().split())
while 1:
    n,m = get()
    if n==m==0: break
    t = [0]
    if n!=0: t += get()
    if m!=0: t += get()
    t.sort()
    print max(t[i+1]-t[i] for i in xrange(n+m)) if n+m>1 else t[1]

Submission status: Accepted

Solution code:
while 1:
	n,m = map(int,raw_input().split())
	if n == m == 0: break
	data = [0]
	if n > 0: data += map(int,raw_input().split())
	if m > 0: data += map(int,raw_input().split())
	data = sorted(data)
	print max(data[i+1]-data[i] for i in range(n+m))

Submission status: Accepted

Solution code:

while True :
    n, m = map(int, input().split())
    if n == 0  and m == 0 :
        break
    car_list = []
    if n != 0 :
        A = list(map(int, input().split()))
        for i in range(n) :
            car_list.append(A[i])
    if m != 0 :
        A = list(map(int, input().split()))
        for i in range(m) :
            car_list.append(A[i])
    car_list.sort()
    car_list.insert(0, 0)
    
    max_car = 0
    for i in range(n+m) :
        if car_list[i+1] - car_list[i] > max_car :
            max_car = car_list[i+1] - car_list[i]
    print(max_car)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    while True:
        L, R = list(map(int, input().strip().split()))
        if L == 0 and R == 0:
            break
            
        arr = set([ 0 ])
        if L > 0:
            arr.update( list(map(int, input().strip().split(' '))) )
        if R > 0:
            arr.update( list(map(int, input().strip().split(' '))) )
        arr = sorted(list(arr))

        maxi = -9999999999
        for i in range(len(arr) - 1):
            maxi = max(maxi, arr[i + 1] - arr[i])

        print(maxi)

Submission status: Accepted

Solution code:
while True:
  n, m = map(int, input().split())
  if n == 0 and m == 0:
    break
  if n != 0 and m != 0:
    t_all = [0] + sorted(list(map(int, input().split())) + list(map(int, input().split())))
  else:
    t_all = [0] + sorted(map(int, input().split()))
  ans = 0
  for i in range(1, n + m + 1):
    ans = max(ans, t_all[i] - t_all[i - 1])
  print(ans)