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. STM32-AFIO

    只有使用了AFIO的事件控制寄存器.AFIO的重映射功能以及外部中断(EXTI)控制寄存器才需要开启AFIO的时钟,STM32参考手册从来没说过使用IO的复用功能就一定要开启AFIO时钟,这是个误区.

  2. 神奇的NOIP模拟赛 T1 LGTB 玩扫雷

    LGTB 玩扫雷 在一个n m 的棋盘上,有位置上有雷(用“*” 表示),其他位置是空地(用“.” 表示).LGTB 想在每个空地上写下它周围8 个方向相邻的格子中有几个雷.请帮助他输出写了之后的棋盘 ...

  3. C++二叉查找树实现及转化为双向链表

    二叉树首先要有树节点 template<class T> class BinaryNode { public: T element; BinaryNode *left; BinaryNod ...

  4. 在Hadoop集群中添加机器和删除机器

    本文转自:http://www.cnblogs.com/gpcuster/archive/2011/04/12/2013411.html 无论是在Hadoop集群中添加机器和删除机器,都无需停机,整个 ...

  5. SharePoint 2013 配置我的网站 图文引导

    博客地址:http://blog.csdn.net/FoxDave 本篇我们来讲述一下关于SharePoint中我的网站(My Sites)相关的东西. 我的网站是SharePoint 2013中面向 ...

  6. C# IList<T>转为DataTable

    public class WebUtil { /// <summary> /// 转换IList<T>为DataTable/// </summary> /// &l ...

  7. dom对象操作Html,Css

    HTML: 1.不要再文档加载完使用document.write,这样会创建新的dom对象,原来的元素将被覆盖. 2.获取元素,通过getElementbyID; getElementbyTag(&q ...

  8. 第八章 标准IO库

    1.IO对象时不可复制或者赋值的:也就是说形参或者返回类型也不能为流类型.如果非要传递或者返回IO对象的的话,则必须传递或者返回指向对象的指针或者引用.如:  ofstream &print( ...

  9. ios开发值json数据文件的存取

    将Json存进本地文件夹   NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainM ...

  10. Security Checklist (路由器安全checklist)

    Security Checklist Website by     Michael Horowitz  Home | Introduction | Router Bugs | Security Che ...