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

题意:

让你给每一个城市找一个塔来覆盖,然后叫你求出最小的覆盖半径,城市和塔都在一条直线上

题解:

我们直接枚举每一个城市,然后二分找一个最近的塔来覆盖

 #include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
typedef long long ll; const int N=1E5+;
int a[N],b[N]; void up(int &a,int b){if(a<b)a=b;} int main(){
int n,m,eda=,edb=;
scanf("%d%d",&n,&m);
F(i,,n)scanf("%d",a+i);
F(i,,m)scanf("%d",b+i);
F(i,,n)if(a[i]!=a[eda])a[++eda]=a[i];//去重
F(i,,m)if(b[i]!=b[edb])b[++edb]=b[i];//去重
int ans=;
F(i,,eda){
int pos=lower_bound(b+,b++edb,a[i])-b-;
int tp=INT_MAX;//找一个最近的塔来更新答案
if(pos>=)tp=min(tp,a[i]-b[pos]);
if(pos<edb)tp=min(tp,b[pos+]-a[i]);
up(ans,tp);
}
printf("%d\n",ans);
return ;
}

Educational Codeforces Round 15_C. Cellular Network的更多相关文章

  1. Educational Codeforces Round 15 Cellular Network

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

  2. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  3. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  4. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  5. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  6. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  7. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  8. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  9. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

随机推荐

  1. css中position中的几个属性

    static  是默认值.任意 position: static; 的元素不会被特殊的定位.一个 static 元素表示它不会被"positioned",一个 position 属 ...

  2. A Truthful (1-ɛ)-Optimal Mechanism for On-demand Cloud Resource Provisioning---INFOCOM 2015

    [标题] [作者] [来源] [对本文评价] [why] 存在的问题 [how] [不足] assumption future work [相关方法或论文] [重点提示] [其它]

  3. Restaurant & Cooking Starter Kit v1.2.1

    项目: using UnityEngine; using System.Collections; namespace VoidGame { public class Constant : MonoBe ...

  4. ZeroMQ中PUB-SUB模式测试

    因为公司有需求,对程序模块之间通信效率有较高的需求.之前公司用的通信组件是ActiveMQ,根据网上公布的测试结果显示其效率比较低, 后来考虑准备在新的项目中开始使用ZeroMQ.看了几天发现用起来比 ...

  5. 为什么new的普通数组用delete 和 delete[]都能正确释放

    由同事推荐的一篇博客: 为何new出的对象数组必须要用delete[]删除,而普通数组delete和delete[]都一样-------_CrtMemBlockHeader 文章解释了delete 内 ...

  6. hbase伪分布

    1.编辑 conf/hbase-env.sh来告知HBase java的安装路径.在这个文件里你还可以设置HBase的运行环境,诸如 heapsize和其他 JVM有关的选项, 还有Log文件地址,等 ...

  7. pthon之异常、文件练习题

    1.在当前目录下查找文件夹“电摄班”,如果不存在则创建2.在电摄班下创建boys.girls.两个txt文件3.将字典中属于电摄班的同学按男女区分,分别放到boys.girls文件中,每个名字在文件中 ...

  8. hihoCoder挑战赛11 A 随机斐波那契

    算了前三项.....发现是个大水题...   #include<stdio.h> int main() { int n; while (~scanf("%d", &am ...

  9. GBDT详解

    GBDT(Gradient Boosting Decision Tree) 又叫 MART(Multiple Additive Regression Tree),是一种迭代的决策树算法,该算法由多棵决 ...

  10. Jquery获得 selection的text 和 option值

    Jquery获得 selection的text 和 option值 <select id="accountStatus" editable="false" ...