C. Cellular Network
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are 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 in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from this tower.

Your task is to find minimal r that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than r.

If r = 0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than r from this tower.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 105) — the number of cities and the number of cellular towers.

The second line contains a sequence of n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates ai are given in non-decreasing order.

The third line contains a sequence of m integers b1, b2, ..., bm ( - 109 ≤ bj ≤ 109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates bj are given in non-decreasing order.

Output

Print minimal r so that each city will be covered by cellular network.

Examples
input
3 2
-2 2 4
-3 0
output
4
input
5 3
1 5 10 14 17
4 11 15
output
3

题意:给你n个城市的坐标和m个塔的坐标 (都在x轴上,非递减的给出)  塔的工作范围为半径为r的圆

问最小的r使得所有的城市都在塔的工作范围内。

题解:枚举每个城市 二分得到最近的塔的位置 取距离差值的max

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
int n,m;
int a[];
int b[];
int main()
{
scanf("%d %d",&n,&m);
for(int i=; i<n; i++)
scanf("%d",&a[i]);
for(int i=; i<m; i++)
scanf("%d",&b[i]);
int ans=;
for(int i=; i<n; i++)
{
int pos=lower_bound(b,b+m,a[i])-b;
if(pos==)
ans=max(ans,b[pos]-a[i]);
else if(pos==m)
ans=max(ans,a[i]-b[pos-]);
else
ans=max(ans,min(b[pos]-a[i],a[i]-b[pos-]));
}
cout<<ans<<endl;
return ;
}

Educational Codeforces Round 15 C 二分的更多相关文章

  1. Educational Codeforces Round 15 C. Cellular Network(二分)

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  2. Educational Codeforces Round 15 A, B , C 暴力 , map , 二分

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Educational Codeforces Round 15 A. Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 15 (A - E)

    比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...

  6. Educational Codeforces Round 61 D 二分 + 线段树

    https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...

  7. Educational Codeforces Round 15 A dp

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Educational Codeforces Round 15 Cellular Network

    Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...

  9. Educational Codeforces Round 15 Powers of Two

    Powers of Two 题意: 让求ai+aj=2的x次幂的数有几对,且i < j. 题解: 首先要知道,排完序对答案是没有影响的,比如样例7 1一对,和1 7一对是样的,所以就可以排序之后 ...

随机推荐

  1. js基础之DOM

    一.创建子节点 发帖在顶部显示: var oBtn = document.getElementById('btn1'); var oUl = document.getElementById('ul1' ...

  2. js字符转换成整型 parseInt()函数规程Number()函数

    今天在做一个js加法的时候,忘记将字符转换成整型,导致将加号认为是连接符,  在运算前要先对字符井行类型转换,使用parseInt()函数   使用Number()将字符转换成int型效果更好

  3. matlab 2012 vs2010混合编程

    电脑配置: 操作系统:window 8.1 Matlab 2012a安装路径:D:\Program Files\MATLAB\R2012a VS2010 : OpenCV 2.4.3:D:\Progr ...

  4. Actioncontext之类的map嵌套,取值

    假设图中最顶端的map设为Actioncontext的map,这种情况,用<s:property value=""/>或者EL表达式取值,可以用#key1.key2.k ...

  5. NSString的几种常用方法

    NSString的几种常用方法   要把 “2011-11-29” 改写成 “2011/11/29”一开始想用ios的时间格式,后来用NSString的方法搞定. [string stringByRe ...

  6. HDU 4737 A Bit Fun

    题意:定义F(i,j)为数组a中从ai到aj的或运算,求使F(i,j)<m的对数. 思路:或运算具有单调性,也就是只增不减,如果某个时刻结果大于等于m了,那么再往后一定也大于等于m.所以可以用两 ...

  7. web api post传一个参数时 值永远是null

    这个问题纠结了我一个早上,不管用什么样的传参方法,走到控制器中,那个参数永远不变的等于null 在网上找了很多解决方案 上面这个是从网上截图的,第一:要将参数标记为[FromBody],变为简单参数 ...

  8. html5 placeholder

    placeholder是html5<input>标签的一个属性,placeholder 属性提供可描述输入字段预期值的提示信息(hint).该提示会在输入字段为空时显示,并会在字段获得焦点 ...

  9. The 1st day with Python

    刚开始实践python,遇到比较多的问题就是函数名.变量名输入错误,比较给力的按无论shell还是terminal给出的错误提示,按图索骥都能在网上找到相关解决办法,简单的自己也能顿悟. 典型的一个是 ...

  10. 在windows上搭建ftp服务

    在控制面板->程序和功能->打开或关闭Windows功能中开启ftp和IIS信息服务管理器 在控制面板->管理工具中打开Internet信息服务管理器->添加ftp站点 建好之 ...