codeforces-702C-Cellular Network
来源:互联网 发布:celtx剧本写作软件 编辑:程序博客网 时间:2024/05/22 00:19
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
二分一下就好了
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cmath>using namespace std;typedef long long ll;int n,m;ll a[100005],b[100005];bool dis(int i,int x,ll val){ return abs(b[i]-a[x])<=val;}bool check(ll val){ int x=0; for(int i=0;i<m;i++) { while(x<n&&dis(i,x,val)) x++; } return (x==n);}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i<n;i++) scanf("%lld",&a[i]); for(int j=0;j<m;j++) scanf("%lld",&b[j]); ll l=0,r=4e9; while(l<r) { ll mid=(l+r)/2; if(check(mid)) { r=mid; } else { l=mid+1; } } printf("%I64d\n",l); } return 0;}
- codeforces-702C-Cellular Network
- codeforces 702C Cellular Network
- codeforces 702C Cellular Network
- 【CodeForces】702C - Cellular Network(二分)
- 【Codeforces】-702C-Cellular Network(二分)
- CodeForces 702 C. Cellular Network(水~)
- codeforces 702C Cellular Network 二分
- codeforces 702C Cellular Network(二分+尺取)
- Educational Codeforces Round 15 C. Cellular Network
- CF 702C Cellular Network
- coderforces 702C Cellular Network(二分)
- Codeforces 702C Cellular Network【二分+思维】CF的题好多二分啊~
- Educational Codeforces Round 15 C. Cellular Network(二分)
- Educational Codeforces Round 15, problem: (C) Cellular Network
- Educational Codeforces Round 15 C. Cellular Network (二分)
- Educational Codeforces Round 15 C Cellular Network(二分)
- Cf Edu 15 C Cellular Network 二分
- Cellular Network LA4731
- codeforces-702B-Powers of Two
- BestCoder Round #85 sum(尺取法)
- Android加载动画系列——NewsLoadingAnim
- Maven生命周期详解
- Linux -- 权限管理
- codeforces-702C-Cellular Network
- CSUOJ 1770 按钮控制彩灯实验(树状数组 || 技巧)
- adb端口占用处理
- SDUT2137数据结构实验之求二叉树后序遍历和层次遍历
- Fragment嵌套Fragment使用的一般框架
- 循环队列的优点缺点
- 验证哥德巴赫猜想
- Scala入门之面向接口编程
- JZOJ4588. 【NOI2016模拟7.7】冷战 + 按秩合并讲解