Problem 887
Heaters
Medium · 20 pts · Array, Binary Search, Two Pointers, Sorting
Problem
Houses and heaters stand at integer positions on a line. Every heater warms all houses within the same radius R of it. Find the smallest R such that every house is warmed by at least one heater. For each house, the nearest heater can be found by binary searching in the sorted heater positions; the answer is the largest of these nearest distances.
Input
The first line contains N and M. The second line contains the N house positions. The third line contains the M heater positions.
Output
Print the minimum radius.
Constraints
1 <= N, M <= 30000; 1 <= positions <= 10^9
Example input
4 2 1 2 3 4 1 4
Example output
1
Explanation
With houses 1 2 3 4 and heaters 1 4, radius 1 lets heater 1 warm houses 1 and 2 and heater 4 warm houses 3 and 4. So the answer is 1.