forked from hubblemd/BinarySearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCellular network
62 lines (52 loc) · 1.1 KB
/
Cellular network
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define pb push_back
#define yes cout << "yes" << endl
#define no cout << "no" << endl
using namespace std;
bool madhav(int mid,vector<int>&city,vector<int>&tower,int n,int m)
{
int cities=0,j=0,i=0;
while(j<m && i<n)
{
if( abs( tower[j] - city[i] ) <= mid)
{
i++;
cities++;
}
else j++; //break;
}
return cities>=n;
}
void solve()
{
int n,m;cin>>n>>m;
vector<int>city(n),tower(m);
for(int i=0;i<n;i++) cin>>city[i];
for(int i=0;i<m;i++) cin>>tower[i];
int low=0,high=2e9,ans=0;
while(low<=high)
{
int mid = low + (high - low) / 2;
if(madhav(mid,city,tower,n,m)==true)
{
ans=mid;
high=mid-1;
}
else low=mid+1;
//cout<<"\n";
}
cout<<ans<<endl;
}
signed main()
{
int t =1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
}