1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < algorithm>
4
+ #include < fstream>
5
+ #include < map>
6
+
7
+ using namespace std ;
8
+
9
+ typedef long long ll;
10
+ // typedef vector<ll> vi;
11
+ // typedef vector<vi> vvi;
12
+ typedef map<ll, ll> dict;
13
+
14
+ ll N;
15
+ // vvi plane(100000, vi(2));
16
+ dict plane;
17
+
18
+ // bool compare(vi p1, vi p2) {
19
+ // return p1[0]<p1[0];
20
+ // }
21
+
22
+ bool cover (ll L) {
23
+ if (L==1 ) return true ;
24
+
25
+ for (dict::iterator it = plane.begin (); it != plane.end (); it++ ) {
26
+ ll x=it->first , y=it->second ;
27
+ for (ll key=x-L+1 ; key<x+L; ++key) {
28
+ if (key==x) continue ;
29
+ if (plane.find (key) != plane.end () ) { // if key exist
30
+ ll y2 = plane[key];
31
+ if (abs (y2-y)<L) {
32
+ return false ;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ return true ;
38
+ }
39
+
40
+ int main () {
41
+ // Unit tests:
42
+
43
+ // ifstream in("in.txt");
44
+ // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
45
+ // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
46
+
47
+ // ofstream out("out.txt");
48
+ // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
49
+ // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
50
+
51
+ while (cin >> N) {
52
+ plane.clear ();
53
+ for (ll i=0 ; i<N; ++i) {
54
+ ll x,y;
55
+ cin >> x >> y;
56
+ plane[x] = y;
57
+ }
58
+ // sort(plane.begin(), plane.begin()+N, compare);
59
+
60
+ ll L=0 , R=4000001 , mid;
61
+ while (R - L != 1 ) {
62
+ mid = (L+R) >> 1 ;
63
+ // cout << R << " " << L<< " " << mid << endl;
64
+ if (cover (mid)) {
65
+ L = mid;
66
+ } else {
67
+ R = mid;
68
+ }
69
+ }
70
+ // for (ll i=0; i<N; ++i) {
71
+ // // ll tmp = max(abs(plane[i][0] - plane[i+1][0]), abs(plane[i][1] -
72
+ // // plane[i+1][1]));
73
+ // // Max = min(tmp, Max);
74
+ // }
75
+ cout << L << endl;
76
+ }
77
+ return 0 ;
78
+ }
0 commit comments