~/algor $ cat problems/ikki-korsatkich-eng-yaqin-ikki-massiv
Closest pair from two arrays
Easy
1000 ms
128 MB
24%
Two arrays sorted in non-decreasing order are given: $a$ of $n$ numbers and $b$ of $m$ numbers. If one number is taken from the first array and one from the second, what is the smallest possible absolute difference $|a_{i} - b_{j}|$?
Input
The first line contains two positive integers: $n$ and $m$.
The second line contains $n$ integers $a_{i}$.
The third line contains $m$ integers $b_{j}$.
Output
One integer — the smallest difference.
Note
$1 \le n, m \le 10^{5}$
$-10^{9} \le a_{i}, b_{j} \le 10^{9}$
both arrays are in non-decreasing order
Examples
Input #1
3 4 1 5 9 3 8 12 20
Output #1
1
Input #2
1 1 4 4
Output #2
0