CodeForces - 702C Cellular Network

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.

Example

Input

3 2-2 2 4-3 0

Output

4

Input

5 31 5 10 14 174 11 15

Output

3贪心,二分都可以,下面是贪心做法。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

int a,b,maxx=0,s;
long long aa[100005],bb[100005];

int suan(long long x)
{
    while(x>bb[s+1]&&s<b)
        s++;
    return min(bb[s+1]-x,abs(x-bb[s]));
}

int main()
{
    scanf("%d%d",&a,&b);
    for(int i=0;i<a;i++)
        scanf("%lld",&aa[i]);
    for(int i=0;i<b;i++)
        scanf("%lld",&bb[i]);
    bb[b]=1e18+1;
    s=0;
    for(int i=0;i<a;i++)
        maxx=max(maxx,suan(aa[i]));
    printf("%d\n",maxx);

    return 0;
}
时间: 2024-10-09 21:18:01

CodeForces - 702C Cellular Network的相关文章

codeforce 702C Cellular Network 二分答案

http://codeforces.com/contest/702 题意:n个村庄,m个机站,问机站最短半径覆盖完所有村庄 思路:直接二分答案 二分太弱,调了半天..... 1 // #pragma comment(linker, "/STACK:102c000000,102c000000") 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <s

codeforces 702C C. Cellular Network(水题)

题目链接: 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

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 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

Educational Codeforces Round 15_C. Cellular Network

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

CodeForce-702C Cellular Network(查找)

Cellular Network CodeForces - 702C 给定 n (城市数量) 和 m (灯塔数量): 给定 a1~an 城市坐标: 给定 b1~bm 灯塔坐标: 求出灯塔照亮的最小半径 r ,使得所有城市都能被照亮. Input 3 2-2 2 4-3 0 Output 4 Input 5 31 5 10 14 174 11 15 Output 3 题解: 首先对于每个城市 a[ i ],找到离它最近的左右两个灯塔  b [ x ] , b [ x-1 ](只有最左或最右灯塔时

cf702C Cellular Network

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

UVA 1456 六 Cellular Network

Cellular Network Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 1456 A cellular network is a radio network made up of a number of cells each served by a base station located in the cell. The base sta

UVALive 4731 Cellular Network

分析: 状态是一些有序的集合,这些集合互不相交,并集为所有区域.显然枚举集合元素是哪些是无法承受的, 写出期望的计算式,会发现一个贪心,当每个集合的大小确定了以后,概率大的优先访问是最优的.容易证明,也符合直觉. 因此先对u从大到小排序.定义状态f[i][j]表示从j开始往后分i组的最小期望. 转移是枚举划分k,则有f[i][j] = min{f[i-1][k]+(k-j)*(u[n]-u[j-1])},k>j 边界f[1][j] = (n-j+1)*(u[n]-u[j-1]) #include

UVA - 1456 Cellular Network

题目大意: 手机在蜂窝网络中的定位是一个基本问题.假设蜂窝网络已经得知手机处于c1, c2,-,cn这些区域中的一个,最简单的方法是同时在这些区域中寻找手机.但这样做很浪费带宽.由于蜂窝网络中可以得知手机在这不同区域中的概率,因此一个折中的方法就是把这些区域分成w组,然后依次访问.比如,已知手机可能位于5个区域中,概率分别为0.3.0.05.0.1.0.3和0.25,w=2,则一种方法是先同时访问{c1,c2,c3},再同时访问{c4,c5},访问区域数的数学期望为3*(0.3+0.05+0.1