#C13132. Smallest Absolute Difference

    ID: 42637 Type: Default 1000ms 256MiB

Smallest Absolute Difference

Smallest Absolute Difference

You are given two arrays of integers. Your task is to compute the smallest absolute difference between any two numbers, where one number is chosen from the first array and the other is chosen from the second array.

If either of the arrays is empty, then the answer is considered to be \(\infty\) (infinity). In this problem, you should output the string INF if one or both arrays are empty.

The problem can be solved efficiently by first sorting both arrays and then using a two-pointer technique to find the minimum difference. The running time complexity should be \(O(n\log n + m\log m)\) due to sorting, where \(n\) and \(m\) are the sizes of the two arrays.

inputFormat

The input is read from standard input and has the following format:

  1. The first line contains two integers \(n\) and \(m\), representing the number of elements in the first and second arrays respectively.
  2. The second line contains \(n\) space-separated integers representing the first array. If \(n = 0\), this line will be empty.
  3. The third line contains \(m\) space-separated integers representing the second array. If \(m = 0\), this line will be empty.

outputFormat

Output a single value to standard output: the smallest absolute difference between any pair of numbers (one from each array). If either array is empty, output the string INF.

## sample
5 5
1 3 15 11 2
23 127 235 19 8
3