-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxSplDist.cpp
66 lines (56 loc) · 1.17 KB
/
MaxSplDist.cpp
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
63
64
65
66
#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
bool isValid(vector<pair<int,int>> v,int dist)
{
int p=-1,miny=1000000,maxy=-1000000;
for(int j=1;j<v.size();j++)
{
while(p+1<j && v[j].first-v[p+1].first>=dist)
{
p++;
if(v[p].second>maxy)
maxy=v[p].second;
if(v[p].second<miny)
miny=v[p].second;
}
if(p!=-1 && abs(miny-v[j].second)>=dist)
return true;
if(p!=-1 && abs(maxy-v[j].second)>=dist)
return true;
}
return false;
}
int binSearch(vector<pair<int,int>> v)
{
sort(v.begin(),v.end());
int l=0,h=1000000;
int ans,mid;
while(l<=h)
{
mid=(l+h)/2;
if(isValid(v,mid))
{
ans=mid;
l=mid+1;
}
else
h=mid-1;
}
return ans;
}
int main()
{
int n,x,y;
cin>>n;
vector<pair <int,int>> v;
for(int i=0;i<n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}
cout<<binSearch(v);
return 0;
}