首页 > Web开发 > 详细

CodeForces - 702C Cellular Network

时间:2017-08-09 14:59:04      阅读:211      评论:0      收藏:0      [点我收藏+]

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 3
1 5 10 14 17
4 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;
}

 

CodeForces - 702C Cellular Network

原文:http://www.cnblogs.com/xibeiw/p/7325212.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!