FlexportOA #5
Collect Points
Estimated HardJudge-ready
Topics (AI-labelled)Binary SearchGreedyTwo Pointers
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.
Input
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
Output the minimum number of seconds.
Example 1
Input:
1 2
5
3 7
Output:
6
Example 2
Input:
2 2
1 9
2 8
Output:
1
Example 3
Input:
2 3
4 1
8 2 6
Output:
4
Editorial
Loading solution…