#abc212c. C - Min Difference

C - Min Difference

Score : 300300 points

问题描述

给定两个序列:A=(A1,A2,,AN)A=(A_1,A_2,\ldots ,A_N),包含 NN 个正整数;以及 B=(B1,,BM)B=(B_1,\ldots ,B_M),包含 MM 个正整数。

要求找出 AA 中的元素与 BB 中的元素之间的最小差值,即 $\displaystyle \min_{1\leq i\leq N}\displaystyle\min_{1\leq j\leq M} \lvert A_i-B_j\rvert$。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given two sequences: A=(A1,A2,,AN)A=(A_1,A_2, \ldots ,A_N) consisting of NN positive integers, and B=(B1,,BM)B=(B_1, \ldots ,B_M) consisting of MM positive integers.

Find the minimum difference of an element of AA and an element of BB, that is, $\displaystyle \min_{ 1\leq i\leq N}\displaystyle\min_{1\leq j\leq M} \lvert A_i-B_j\rvert$.

Constraints

  • 1N,M2×1051 \leq N,M \leq 2\times 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • 1Bi1091 \leq B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \ldots ANA_N

B1B_1 B2B_2 \ldots BMB_M

Output

Print the answer.

Sample Input 1

2 2
1 6
4 9

Sample Output 1

2

Here is the difference for each of the four pair of an element of AA and an element of BB: 14=3\lvert 1-4\rvert=3, 19=8\lvert 1-9\rvert=8, 64=2\lvert 6-4\rvert=2, and 69=3\lvert 6-9\rvert=3. We should print the minimum of these values, or 22.

Sample Input 2

1 1
10
10

Sample Output 2

0

Sample Input 3

6 8
82 76 82 82 71 70
17 39 67 2 45 35 22 24

Sample Output 3

3

update @ 2024/3/10 09:27:07