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

题目链接:http://codeforces.com/contest/702/problem/C

用二分法求解,因为最大不会超过2e9,所以l=0,r略大于2e9,后面就是二分法了。

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
int n,m;
cin >> n >> m;
long long a[n],b[m];
for(int i = ; i < n; i++)
cin >> a[i];
for(int i = ; i < m; i++)
cin >> b[i];
long long l = , r = 2e9+;
long long mid;
while(l<r)
{
mid = (l+r)/;
int flag = ;
int x = ;
for(int i = ; i < n; i++)
{
if(x > m)
{
flag = ;
break;
}
if(abs(a[i]-b[x]) <= mid)
continue;
else
{
x++;
i--;
}
}
if(flag == )
l = mid+;
else
r = mid;
//cout << l << ' ' << r << endl;
}
cout << l;
return ;
}

查看代码

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

  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. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  3. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  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. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

  6. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Codeforces Educational Codeforces Round 3 B. The Best Gift 水题

    B. The Best Gift 题目连接: http://www.codeforces.com/contest/609/problem/B Description Emily's birthday ...

  8. codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

    题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...

  9. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

随机推荐

  1. Oracle中用一个表的数据更新另一个表的数据

    update tbl1 a   set (a.col1, a.col2) = (select b.col1, b.col2                              from tbl2 ...

  2. android 内存溢出问题分析

      最近的项目中,内存一直再增长,但是不知道是什么问题,导致内存溢出,在网上看到了这么一篇关于内存分析与管理的文章,解决了部分问题,感觉这篇文 章还不错,就转帖到我的blog上了,希望对大家有所帮助. ...

  3. SQL查询时间去除非工作日...

    CREATE FUNCTION [f_WorkDayADD]( @date datetime, --基础日期 @workday int --要增加的工作日数 )RETURNS datetime AS ...

  4. Qt之国际化(系统文本-QMessageBox按钮、QLineEdit右键菜单等)

    简介 使用Qt的时候,经常会遇到英文问题,例如:QMessageBox中的按钮.QLineEdit.QSpinBox.QScrollBar中的右键菜单等.通常情况下,我们软件都不会是纯英文的,那么如何 ...

  5. UVa 12265 (单调栈) Selling Land

    紫书上分析了很多很多,超详细,= ̄ω ̄= 每扫描一行可以计算一个height数组,表示从这块空地向上延伸多少块空地,而且这个数组可以逐行递推. 首先对于每一行来说维护一个单调栈,栈里放的是矩形的左上角 ...

  6. UVa 1607 (二分) Gates

    这道题真的有点“神”啊.= ̄ω ̄= 因为输入都是x,所以整个电路的功能一共就四种:0, 1, x,!x 所以就确定了这样一个事实:如果电路的输出是常数,那么所有的输入都可以优化成常数. 否则,只需要将 ...

  7. Jenkins+Maven+SVN搭建自动部署、自动测试环境

    .打开http://10.3.15.78:8080/jenkins/,第一次进入里面没有数据,我们需要创建job,我们这有2个项目,需要创建2个job.http://10.3.34.163:9890/ ...

  8. linux shared lib 使用与编译

    一.              动态链接库的原理及使用 Linux提供4个库函数.一个头文件dlfcn.h以及两个共享库(静态库libdl.a和动态库libdl.so)支持动态链接. Ø        ...

  9. I.MX6 uSDHC SD card register

    /**************************************************************************** * I.MX6 uSDHC SD card ...

  10. 文件IO

    在unix世界中视一切为文件,无论最基本的文本文件还是网络设备或是u盘,在内核看来它们的本质都是一样的.大多数文件IO操作只需要用到5个函数:open . read . write . lseek 以 ...