Educational Codeforces Round 15_C. Cellular Network

來源:互聯網
上載者:User

標籤:

C. Cellular Networktime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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.

Examplesinput
3 2
-2 2 4
-3 0
output
4
input
5 3
1 5 10 14 17
4 11 15
output
3

 

 

 

題意:

讓你給每一個城市找一個塔來覆蓋,然後叫你求出最小的覆蓋半徑,城市和塔都在一條直線上

題解:

我們直接枚舉每一個城市,然後二分找一個最近的塔來覆蓋

 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 using namespace std; 4 typedef long long ll; 5  6 const int N=1E5+7; 7 int a[N],b[N]; 8  9 void up(int &a,int b){if(a<b)a=b;}10 11 int main(){12     int n,m,eda=1,edb=1;13     scanf("%d%d",&n,&m);14     F(i,1,n)scanf("%d",a+i);15     F(i,1,m)scanf("%d",b+i);16     F(i,2,n)if(a[i]!=a[eda])a[++eda]=a[i];//去重17     F(i,2,m)if(b[i]!=b[edb])b[++edb]=b[i];//去重18     int ans=0;19     F(i,1,eda){20         int pos=lower_bound(b+1,b+1+edb,a[i])-b-1;21         int tp=INT_MAX;//找一個最近的塔來更新答案22         if(pos>=1)tp=min(tp,a[i]-b[pos]);23         if(pos<edb)tp=min(tp,b[pos+1]-a[i]);24         up(ans,tp);25     }26     printf("%d\n",ans);27     return 0;28 }
View Code

 

Educational Codeforces Round 15_C. Cellular Network

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.