D. [R7D]最小极差

    Type: Default 1000ms 512MiB

[R7D]最小极差

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

时空限制

1S/512M

题目描述

给定一个长度为 nn 的整数数组 AA 和一个长度为 mm 的整数数组 BB

对于 1in1\leq i\leq n 的每个 ii,分别在 1jm1\leq j\leq m 中选择 jj,构造长度为 nn 的整数数组 Ci=Ai+BjC_i=A_i+B_j

定义 CC 的极差为 max{Ci}min{Ci}\max\{C_i\}-\min\{C_i\},求 CC 的极差的最小值。

格式

输入格式

第一行包含两个整数 nnmm,分别表示数组 AA 的长度和数组 BB 的长度。

第二行包含 nn 个整数 AiA_i

第三行包含 mm 个整数 BiB_i

输出格式

输出一个整数表示 max{Ci}min{Ci}\max\{C_i\}-\min\{C_i\} 的最小值。

样例

样例输入 #1

5 3
1 3 4 5 1
4 3 7

样例输出 #1

1

样例解释 #1

C={8,7,8,8,8}C=\{8,7,8,8,8\} 时极差最小,其中 C1=A1+B3=8C_1=A_1+B_3=8C2=A2+B1=7C_2=A_2+B_1=7C3=A3+B1=8C_3=A_3+B_1=8C4=A4+B2=8C_4=A_4+B_2=8C5=A5+B3=8C_5=A_5+B_3=8

数据规模

对于 40%40\% 的数据,n500n\leq 500

另有 20%20\% 的数据,Ai,Bi1000A_i,B_i\leq 1000

对于 100%100\% 的数据,1n3×1051\leq n\leq 3\times 10^51m101\leq m\leq 101Ai,Bi10181\leq A_i,B_i\leq 10^{18}

代码源挑战赛 Round 7

Not Attended
Status
Done
Rule
DMY
Problem
6
Start at
2025-4-11 20:00
End at
2025-4-11 21:30
Duration
1.5 hour(s)
Host
Partic.
505