Codeforces 702C C. Cellular Network (water problem)

Source: Internet
Author: User

Topic Links:

C. Cellular Network

Time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You is 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 on the same way-they provide cellular network for all cities, which be located at the distance which is No more than R from the This tower.

Your task is to find minimal R , all city have been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which are no more than R.

If R = 0 Then A-tower provides cellular network only in the where it is located. One tower can provide cellular network for any number of cities, but all these cities must are at the distance which are no More than R from the This tower.

Input

The first line contains the positive integers n and m (1≤ n, m ≤ 5)-the number of cities and the number of cellular towers.

The second line contains a sequence Of  n  integers  a 1, a 2, ..., a n   (-109≤ a i ≤109)-the coordinates of cities. It is allowed, that there was any number of cities in the same point. All Coordinates  a I  are given in Non-decreasing order.

The third line contains a sequence of m integers b1, b2, ..., b m ( -9≤ bJ ≤109)-the coordinates of cellular towers. It is allowed, that there was any number of towers in the same point. All coordinates bJ is given in non-decreasing order.

Output

Print minimal R So, each city would be covered by cellular network.

Examplesinput
3 2
-2 2 4
-3 0
Output
4
Input
5 3
1 5 10) 14 17
4 11 15
Output
3

Test instructions

For each city to find a supply, ask the smallest radius is how much;

Ideas:

two points;

AC Code:

/************************************************┆┏┓┏┓┆┆┏┛┻━━━┛┻┓┆┆┃┃┆┆┃━┃┆┆┃┳┛┗┳┃┆┆┃  ┃┆┆┃┻┃┆┆┗━┓┏━┛┆┆┃┃┆┆┃┗━━━┓┆┆┃ac Horse ┣┓┆┆┃┏┛┆┆┗┓┓┏━┳┓┏┛┆ ┆┃┫┫┃┫┫┆┆┗┻┛┗┻┛┆************************************************ * * #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h > #include <stack>using namespace std, #define for (i,j,n) for (int i=j;i<=n;i++) #define MST (SS,B) memset (ss,b    , sizeof (SS)); typedef long LONG ll;template<class t> void Read (t&num) {char CH; bool F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ';    f= ch== '-', Ch=getchar ()); for (num=0;    ch>= ' 0 ' &&ch<= ' 9 '; num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);}    int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0"); return;} while (p) stk[++ TP] = P%10, p/=10;    while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');} Const LL Mod=1e9+7;const double Pi=acos ( -1.0); const int INF=1E9;CONST int N=1e5+10;const int maxn= (1<<8); Const Doub    Le eps=1e-8;int a[n],b[n],n,m;int check2 (int x) {int l=1,r=m;        while (l<=r) {int mid= (L+R) >>1;        if (b[mid]>x) r=mid-1;    else l=mid+1;    } if (r==0) r=1; return r;}    int check1 (int x) {int l=1,r=m;        while (l<=r) {int mid= (L+R) >>1;        if (b[mid]<x) l=mid+1;    else r=mid-1;    } if (l>m) l=m; return l;}        int main () {read (n); read (m);        for (i,1,n) read (A[i]);        for (i,1,m) read (B[i]);        int ans=0;            for (i,1,n) {int l=check1 (a[i]);            int R=check2 (a[i]);            cout<<l<< "" <<r<<endl;            int Temp=min (ABS (B[l]-a[i]), ABS (B[r]-a[i));        Ans=max (ans,temp);        } cout<<ans<<endl; return 0;}

  

Codeforces 702C C. Cellular Network (water problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.