cswork / OA打开练习工作台

FlexportOA #5

Collect Points

估计困难可在线判题

考点(AI 标注)二分查找贪心调度双指针滑窗

n players move simultaneously and independently on a number line, each moving at most one unit per second. A point is collected once any player visits it. Find the minimum number of seconds needed to collect all points.

输入格式

The first line contains n m (1≤n,m≤100000); the second line contains n player coordinates; the third line contains m point coordinates. All coordinates are integers in 1..10^9. The input is not guaranteed to be sorted.

输出格式

Output the minimum number of seconds.

样例 1

输入:

1 2
5
3 7

输出:

6

样例 2

输入:

2 2
1 9
2 8

输出:

1

样例 3

输入:

2 3
4 1
8 2 6

输出:

4