C. Cellular NetworkTime limit per test3 secondsmemory limit per testMegabytesinputStandard InputOutputStandard Output
You is given n points on the straight line-the positions (x-coordinates) of the cities and m points on the same line-the positions ( x-coordinates) of the cellular towers. All towers work on the same way-they provide cellular network for all cities, which be located at the distance which is No more than R from the This tower.
Your task is to find minimal R , all city have been provided by cellular network, i.e. for each city th ere is at least one cellular tower at the distance which are no more than R.
If R = 0 Then A-tower provides cellular network only in the where it is located. One tower can provide cellular network for any number of cities, but all these cities must are at the distance which are no More than R from the This tower.
Input
The first line contains the positive integers n and m (1≤ n, m ≤1 05)-the number of cities and the number of cellular towers.
the second line contains a sequence of n integers Span class= "Tex-span" > a 1, a 2, ..., a Sub class= "Lower-index" > n (-109≤ a i ≤109)-the coordinates of cities. It is allowed, that there was any number of cities in the same point. All coordinates a I is given in non-decreasing Order.
The third line contains a sequence of m integers b1, b2, ..., b m ( -9≤ bJ ≤109)-the coordinates of cellular towers. It is allowed, that there was any number of towers in the same point. All coordinates bJ is given in non-decreasing order.
Output
Print minimal R So, each city would be covered by cellular network.
ExamplesInput
3 2
-2 2 4
-3 0
Output
4
Input
5 3
1 5 10) 14 17
4 11 15
Output
3
Title Link: Http://codeforces.com/contest/702/problem/C
The two-way solution, because the maximum will not exceed 2e9, so l=0,r slightly greater than 2e9, the second is the dichotomy.
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 using namespacestd;6 intMain ()7 {8 intn,m;9CIN >> N >>m;Ten Long LongA[n],b[m]; One for(inti =0; I < n; i++) ACIN >>A[i]; - for(inti =0; I < m; i++) -CIN >>B[i]; the Long LongL =0, R = 2e9+2; - Long Longmid; - while(l<R) - { +Mid = (l+r)/2; - intFlag =0; + intx =0; A for(inti =0; I < n; i++) at { - if(X >m) - { -Flag =1; - Break; - } in if(ABS (A[i]-b[x]) <=mid) - Continue; to Else + { -X + +; thei--; * } $ }Panax Notoginseng if(Flag = =1) -L = mid+1; the Else +R =mid; A //cout << L << ' << R << Endl; the } +cout <<l; - return 0; $}
View Code
Codeforces educational codeforces Round C. Cellular Network