Problem:
博覧会
問題
JOI 市では,とある大規模な博覧会を開催することになった.
今回の博覧会には 2 つのテーマがあり,JOI 市にある N 個の展示施設でそれぞれ,
2 つのテーマのうちどちらか一方に沿った展示を行う予定である.
施設の位置は平面座標 (x, y) で表される.位置 (x, y) にある施設から (x′ , y′) にある施設まで移動するためには, |x − x′| + |y − y′| だけの時間がかかる (整数 a に対して,
|a| で a の絶対値を表す).同一テーマ内での統一感を出すため,および一方のテーマのみに関心を持つ人に不便を感じさせないために,同一のテーマで展示を行っている 2 つの施設の間の移動時間がなるべく短くなるようにテーマを割りふりたい.すべての展示施設に同じテーマを割りふらない限り, どのようにテーマを割りふってもよい.
同一のテーマで展示を行っている 2 つの施設の間の移動時間の最大値を M とする. N 個の展示施設の位置が与えられたとき, M の最小値を求めるプログラムを作成せよ.
入力
入力の 1 行目には, 施設の個数 N(3 ≤ N ≤ 100000 = 10
5
) が書かれている.入力のi + 1 行目 (1 ≤ i ≤ N) には,各施設の座標を表す 2 つの整数 x
i
, y
i
(|x
i
| ≤ 100000 = 10
5
, |y
i
| ≤ 100000 = 10
5
) が空白区切りで書かれている.これは,i 個目の施設の座標が(x
i
, y
i
) であることを表す. 同一の座標に 2 つ以上の施設が存在することはない.
採点用データのうち,配点の 40% 分については, N ≤ 2000 である.
出力
出力は 1 行のみからなる.同一のテーマで展示を行っている 2 つの施設間の移動時間の最大値 M の最小値を出力せよ.
入出力例
入力例 1
5
0 0
1 0
-1 -2
0 1
-1 1
出力例 1
3
この場合,たとえば座標 (0, 0), (1, 0), (0, 1) にある施設に一方のテーマを,(−1, −2),
(−1, 1) にある施設にもう一方のテーマを割りふると,同一のテーマで展示を行う 2
つの施設間の移動時間はすべて 3 以下になる.移動時間をすべて 2 以下にすることはできないので,3 を出力する.
上記問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int x[100000], y[100000], n, mx, my; bool unused[100000];
int solve(int lx, int ly, int rx, int ry) {
	for (int i = 0; i < n; i++)unused[i] = false;
	for (int i = 0; i < n; i++) {
		if (lx <= x[i] && x[i] <= rx && ly <= y[i] && y[i] <= ry)unused[i] = true;
	}
	int ex = 1000000, ey = 1000000, sx = 0, sy = 0;
	for (int i = 0; i < n; i++) { if (unused[i] == false) { ex = min(ex, x[i]); ey = min(ey, y[i]); sx = max(sx, x[i]); sy = max(sy, y[i]); } }
	return max(sx - ex, sy - ey);
}
bool solve(int r) {
	return (solve(0, 0, r, r) <= r || solve(0, my - r, r, my) <= r || solve(mx - r, 0, mx, r) <= r || solve(mx - r, my - r, mx, my) <= r);
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i]; int r1 = x[i] - y[i], r2 = x[i] + y[i]; x[i] = r1; y[i] = r2; mx = min(mx, x[i]); my = min(my, y[i]);
	}
	for (int i = 0; i < n; i++) { x[i] -= mx; y[i] -= my; }mx = 0; my = 0;
	for (int i = 0; i < n; i++) { mx = max(mx, x[i]); my = max(my, y[i]); }
	int L = 0, R = 1000000, M;
	while (true) {
		M = (L + R) / 2; bool U1 = solve(M - 1), U2 = solve(M);
		if (U1 == false && U2 == true) { cout << M << endl; break; }
		if (U1 == true)R = M;
		if (U2 == false)L = M;
	}
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 4312
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

/**
 * 変数説明:
 *   uma, umi : 全点について u = x + y の最大・最小
 *   vma, vmi : 全点について v = x - y の最大・最小
 */
static int uma, umi, vma, vmi;

/**
 * da(u,v): 現在の (u,v) から最適にテーマ分け（２グループ）した際、
 *           (u,v) が属するグループ内での最大距離（マンハッタン距離の変換後）が
 *           もう一方のグループとの境界距離で評価したときの最小値を返す。
 */
int da(int u, int v) {
    // グループA: 境界は (uma, vma) と (umi, vmi) の線分
    int d1 = max(uma - u, vma - v);
    int d2 = max(u - umi, v - vmi);
    return min(d1, d2);
}

/**
 * db(u,v): 同様にもう一つのグループ分けパターンで評価
 */
int db(int u, int v) {
    // グループB: 境界は (uma, vmi) と (umi, vma) の線分
    int d1 = max(uma - u, v - vmi);
    int d2 = max(u - umi, vma - v);
    return min(d1, d2);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int> u(n), v(n);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        // (x,y) を 45° 回転しマンハッタン距離の最大化問題に帰着
        u[i] = x + y;
        v[i] = x - y;
        if (i == 0) {
            uma = umi = u[i];
            vma = vmi = v[i];
        } else {
            uma = max(uma, u[i]);
            umi = min(umi, u[i]);
            vma = max(vma, v[i]);
            vmi = min(vmi, v[i]);
        }
    }

    // ２つの分け方それぞれの最大「最小距離」を求める
    int bestA = 0, bestB = 0;
    for (int i = 0; i < n; ++i) {
        bestA = max(bestA, da(u[i], v[i]));
        bestB = max(bestB, db(u[i], v[i]));
    }

    // ２パターンのうち小さいほうが答え
    cout << min(bestA, bestB) << "\n";
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3732
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e9 + 1001010;
const ll llINF = (long long)4e18 + 22000020;
const string endn = "\n";
template <class T> inline auto vector2(size_t i, size_t j, const T &init = T()) {return vector(i, vector<T>(j, init));}
const string ELEM_SEPARATION = " ", VEC_SEPARATION = endn;
template<class T> istream& operator >>(istream &i, vector<T> &A) {for(auto &I : A) {i >> I;} return i;}
template<class T> ostream& operator <<(ostream &o, const vector<T> &A) {int i=A.size(); for(const auto &I : A){o << I << (--i ? ELEM_SEPARATION : "");} return o;}
template<class T> ostream& operator <<(ostream &o, const vector<vector<T>> &A) {int i=A.size(); for(const auto &I : A){o << I << (--i ? VEC_SEPARATION : "");} return o;}
template<class T> vector<T>& operator ++(vector<T> &A, int n) {for(auto &I : A) {I++;} return A;}
template<class T> vector<T>& operator --(vector<T> &A, int n) {for(auto &I : A) {I--;} return A;}
template<class T, class U> bool chmax(T &a, const U &b) {return ((a < b) ? (a = b, true) : false);}
template<class T, class U> bool chmin(T &a, const U &b) {return ((a > b) ? (a = b, true) : false);}
ll floor(ll a, ll b){if (b < 0) a = -a, b = -b; if(a >= 0) return a / b; else return (a + 1) / b - 1;}
ll ceil(ll a, ll b){if (b < 0) a = -a, b = -b; if(a > 0) return (a - 1) / b + 1; else return a / b;}
ll bit(unsigned long long val, unsigned long long digit){return (val >> digit) & 1;}
#ifdef DEBUG
#include <debug_slephy.cpp>
#else
#define debug(...)
#endif
// ================================== ここまでテンプレ ==================================

template<class Judgement>
ll binary_search_ll(ll ok, ll ng, Judgement judge){
    auto need_continue = [&]() -> bool {
        if(ok > ng) return((__int128_t)ok - (__int128_t)ng > 1);
        else return ((__int128_t)ng - (__int128_t)ok > 1);
    };
    while(need_continue()){
        ll mid = ((__int128_t)ok + (__int128_t)ng) / 2;
        if(judge(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
};
bool is_between(ll inf, ll n, ll sup){return(inf <= n && n <= sup);}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n; cin >> n;
    vector<ll> x(n), y(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    {
        vector<ll> X(n), Y(n);
        for(int i = 0; i < n; i++){
            X[i] = x[i] - y[i];
            Y[i] = x[i] + y[i];
        }
        x = move(X);
        y = move(Y);
    }

    ll min_x = *min_element(x.begin(), x.end());
    ll max_x = *max_element(x.begin(), x.end());
    ll min_y = *min_element(y.begin(), y.end());
    ll max_y = *max_element(y.begin(), y.end());

    auto judge = [&](ll k) -> bool {
        bool ok1 = true; // {min_x, min_y}, {max_x, max_y}
        bool ok2 = true; // {min_x, max_y}, {max_x, min_y}

        for(int i = 0; i < n; i++){
            ok1 &= (is_between(min_x, x[i], min_x + k) && is_between(min_y, y[i], min_y + k)
                ||  is_between(max_x - k, x[i], max_x) && is_between(max_y - k, y[i], max_y));
            ok2 &= (is_between(min_x, x[i], min_x + k) && is_between(max_y - k, y[i], max_y)
                ||  is_between(max_x - k, x[i], max_x) && is_between(min_y, y[i], min_y + k));
        }

        return (ok1 || ok2);
    };

    ll ans = binary_search_ll(1e6, 0, judge);
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6252
final_rank: 16

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> w(n), v(n);
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        w[i] = x + y;
        v[i] = x - y;
    }
    ll wmx = w[0], wmi = w[0];
    ll vmx = v[0], vmi = v[0];
    for (int i = 0; i < n; i++) {
        wmx = max(wmx, w[i]), wmi = min(wmi, w[i]);
        vmx = max(vmx, v[i]), vmi = min(vmi, v[i]);
    }
    ll L = -1, R = 1e6;
    auto check = [&](ll x) -> bool {
        if (wmi + x >= wmx) {
            for (int i = 0; i < n; i++) {
                if (min(v[i] - vmi, vmx - v[i]) > x) return false;
            }
            return true;
        }
        if (vmi + x >= vmx) {
            for (int i = 0; i < n; i++) {
                if (min(w[i] - wmi, wmx - w[i]) > x) return false;
            }
            return true;
        }
        // wmxとvmxが同じグループ
        {
            bool ok = true;
            for (int i = 0; i < n; i++) {
                ll d1 = max(wmx - w[i], vmx - v[i]);
                ll d2 = max(w[i] - wmi, v[i] - vmi);
                if (min(d1, d2) > x) {
                    ok = false;
                    break;
                }
            }
            if (ok) return true;
        }
        // wmxとvmiが同じグループ
        {
            bool ok = true;
            for (int i = 0; i < n; i++) {
                ll d1 = max(wmx - w[i], v[i] - vmi);
                ll d2 = max(w[i] - wmi, vmx - v[i]);
                if (min(d1, d2) > x) {
                    ok = false;
                    break;
                }
            }
            if (ok) return true;
        }
        return false;
    };
    while (R - L > 1) {
        ll mid = (L + R) / 2;
        if (check(mid)) R = mid;
        else L = mid;
    }
    cout << R << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4608
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, n) for(int i = int(l); i < int(n); i++)

lint inf = 1e18;

int n;
lint x[101010], y[101010];

bool solve_small(lint m){
    lint r = -inf, l = inf;
    lint u = -inf, d = inf;
    
    rep(i, n){
        r = max(r, x[i]);
        l = min(l, x[i]);
        u = max(u, y[i]);
        d = min(d, y[i]);
    }
    rep(i, n){
        if(abs(x[i] - l) <= m && abs(y[i] - u) <= m) continue;
        if(abs(x[i] - r) <= m && abs(y[i] - d) <= m) continue;
        return false;
    }
    return true;
}

bool solve(lint m){
    bool ans = solve_small(m);
    rep(i, n){
        x[i] *= -1;
    }
    ans |= solve_small(m);
    rep(i, n){
        x[i] *= -1;
    }
    return ans;
}

int main(){
    cin >> n;
    rep(i, n){
        lint a, b;
        cin >> a >> b;
        x[i] = a + b;
        y[i] = a - b;
    }
    
    lint ng = 0, ok = 1e9;
    while(abs(ok - ng) > 1){
        lint mid = (ng + ok) / 2;
        
        if(solve(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    
    cout << ok << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 4872
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int N;
struct Point{
    int x;
    int y;
    int num;
    Point(){}
    Point(int _x,int _y,int _num):x(_x),y(_y),num(_num){}
    
};
vector<Point> vp;

bool is_ok(int d){
   // cout<<d<<endl;
    vector<Point> vpn;
    vector<Point> vpe1;
    vector<Point> vpe2;
    for(int i=0;i<N;i++){
        if(vp[i].x-vp[0].x<=d){
            vpn.push_back(vp[i]);
        }else{
            vpe1.push_back(vp[i]);
            vpe2.push_back(vp[i]);
        }
    }
    /*
    cout<<"vpn ";
    for(int i=0;i<vpn.size();i++){
        cout<<vpn[i].x<<":"<<vpn[i].y<<" ";
    }
    */
    
    sort(vpn.begin(),vpn.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    for(int i=0;i<vpn.size();i++){
        if(vpn[i].y-vpn[0].y>d){
            vpe1.push_back(vpn[i]);
        }
        if(vpn.back().y-vpn[i].y>d){
            vpe2.push_back(vpn[i]);
        }
    }
    /*
    cout<<"vpe1 ";
    for(int i=0;i<vpe1.size();i++){
        cout<<vpe1[i].x<<":"<<vpe1[i].y<<" ";
    }
    cout<<"vpe2 ";
    for(int i=0;i<vpe2.size();i++){
        cout<<vpe2[i].x<<":"<<vpe2[i].y<<" ";
    }
    cout<<endl;
    */
    
    
    if(vpe1.empty()||vpe2.empty()){
        return true;
    }
    
    
    
    bool flag1=true;
    bool flag2=true;
    
    sort(vpe1.begin(),vpe1.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    
    if(vpe1.back().x-vpe1[0].x>d){
        flag1=false;
    }
    sort(vpe1.begin(),vpe1.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    if(vpe1.back().y-vpe1[0].y>d){
        flag1=false;
    }
    
    sort(vpe2.begin(),vpe2.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    
    if(vpe2.back().x-vpe2[0].x>d){
        flag2=false;
    }
    sort(vpe2.begin(),vpe2.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    if(vpe2.back().y-vpe2[0].y>d){
        flag2=false;
    }
    
    vpn.clear();
    vpe1.clear();
    vpe2.clear();
    
    
    for(int i=0;i<N;i++){
        if(vp.back().x-vp[i].x<=d){
            vpn.push_back(vp[i]);
        }else{
            vpe1.push_back(vp[i]);
            vpe2.push_back(vp[i]);
        }
    }
    /*
    cout<<"vpn ";
    for(int i=0;i<vpn.size();i++){
        cout<<vpn[i].x<<":"<<vpn[i].y<<" ";
    }
    cout<<"vpe1 ";
    for(int i=0;i<vpe1.size();i++){
        cout<<vpe1[i].x<<":"<<vpe1[i].y<<" ";
    }
    cout<<"vpe2 ";
    for(int i=0;i<vpe2.size();i++){
        cout<<vpe2[i].x<<":"<<vpe2[i].y<<" ";
    }
    cout<<endl;
    */
    
    
    
    sort(vpn.begin(),vpn.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    for(int i=0;i<vpn.size();i++){
        if(vpn[i].y-vpn[0].y>d){
            vpe1.push_back(vpn[i]);
        }
        if(vpn.back().y-vpn[i].y>d){
            vpe2.push_back(vpn[i]);
        }
    }
    
    if(vpe1.empty()||vpe2.empty()){
        return true;
    }
    
    
    bool flag3=true;
    bool flag4=true;
    
    sort(vpe1.begin(),vpe1.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    
    if(vpe1.back().x-vpe1[0].x>d){
        flag3=false;
    }
    sort(vpe1.begin(),vpe1.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    if(vpe1.back().y-vpe1[0].y>d){
        flag3=false;
    }
    
    sort(vpe2.begin(),vpe2.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    
    if(vpe2.back().x-vpe2[0].x>d){
        flag4=false;
    }
    sort(vpe2.begin(),vpe2.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    if(vpe2.back().y-vpe2[0].y>d){
        flag4=false;
    }
    
    
   
    
    return flag1||flag2||flag3||flag4;
    
 
    
}


int main(){

    cin>>N;
    vp.resize(N);
    int x,y;
    for(int i=0;i<N;i++){
        cin>>x>>y;
        vp[i]=Point(x-y,x+y,i);
    }
    
    sort(vp.begin(),vp.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    /*
    for(int i=0;i<vp.size();i++){
        cout<<vp[i].x<<" : "<<vp[i].y<<" ";
    }
    cout<<endl;
     */
    
    
    
    int ng=-1;
    int ok=500050;
    int mid;
    
    while(ok-ng>1){
        mid=(ok+ng)/2;
        if(is_ok(mid)){
            ok=mid;
        }else{
            ng=mid;
        }
    }
    cout<<ok<<endl;
  
    
}
accuracy: 1
time_ms: 370
memory_kb: 7548
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int N;
struct Point{
    int x;
    int y;
    int num;
    Point(){}
    Point(int _x,int _y,int _num):x(_x),y(_y),num(_num){}
    
};
vector<Point> vp;

bool is_ok(int d){
   // cout<<d<<endl;
    vector<Point> vpn;
    vector<Point> vpe1;
    vector<Point> vpe2;
    for(int i=0;i<N;i++){
        if(vp[i].x-vp[0].x<=d){
            vpn.push_back(vp[i]);
        }else{
            vpe1.push_back(vp[i]);
            vpe2.push_back(vp[i]);
        }
    }
    /*
    cout<<"vpn ";
    for(int i=0;i<vpn.size();i++){
        cout<<vpn[i].x<<":"<<vpn[i].y<<" ";
    }
    */
    
    sort(vpn.begin(),vpn.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    for(int i=0;i<vpn.size();i++){
        if(vpn[i].y-vpn[0].y>d){
            vpe1.push_back(vpn[i]);
        }
        if(vpn.back().y-vpn[i].y>d){
            vpe2.push_back(vpn[i]);
        }
    }
    /*
    cout<<"vpe1 ";
    for(int i=0;i<vpe1.size();i++){
        cout<<vpe1[i].x<<":"<<vpe1[i].y<<" ";
    }
    cout<<"vpe2 ";
    for(int i=0;i<vpe2.size();i++){
        cout<<vpe2[i].x<<":"<<vpe2[i].y<<" ";
    }
    cout<<endl;
    */
    
    
    if(vpe1.empty()||vpe2.empty()){
        return true;
    }
    
    
    
    bool flag1=true;
    bool flag2=true;
    
    sort(vpe1.begin(),vpe1.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    
    if(vpe1.back().x-vpe1[0].x>d){
        flag1=false;
    }
    sort(vpe1.begin(),vpe1.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    if(vpe1.back().y-vpe1[0].y>d){
        flag1=false;
    }
    
    sort(vpe2.begin(),vpe2.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    
    if(vpe2.back().x-vpe2[0].x>d){
        flag2=false;
    }
    sort(vpe2.begin(),vpe2.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    if(vpe2.back().y-vpe2[0].y>d){
        flag2=false;
    }
    
    vpn.clear();
    vpe1.clear();
    vpe2.clear();
    
    
    for(int i=0;i<N;i++){
        if(vp.back().x-vp[i].x<=d){
            vpn.push_back(vp[i]);
        }else{
            vpe1.push_back(vp[i]);
            vpe2.push_back(vp[i]);
        }
    }
    /*
    cout<<"vpn ";
    for(int i=0;i<vpn.size();i++){
        cout<<vpn[i].x<<":"<<vpn[i].y<<" ";
    }
    cout<<"vpe1 ";
    for(int i=0;i<vpe1.size();i++){
        cout<<vpe1[i].x<<":"<<vpe1[i].y<<" ";
    }
    cout<<"vpe2 ";
    for(int i=0;i<vpe2.size();i++){
        cout<<vpe2[i].x<<":"<<vpe2[i].y<<" ";
    }
    cout<<endl;
    */
    
    
    
    sort(vpn.begin(),vpn.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    for(int i=0;i<vpn.size();i++){
        if(vpn[i].y-vpn[0].y>d){
            vpe1.push_back(vpn[i]);
        }
        if(vpn.back().y-vpn[i].y>d){
            vpe2.push_back(vpn[i]);
        }
    }
    
    if(vpe1.empty()||vpe2.empty()){
        return true;
    }
    
    
    bool flag3=true;
    bool flag4=true;
    
    sort(vpe1.begin(),vpe1.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    
    if(vpe1.back().x-vpe1[0].x>d){
        flag3=false;
    }
    sort(vpe1.begin(),vpe1.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    if(vpe1.back().y-vpe1[0].y>d){
        flag3=false;
    }
    
    sort(vpe2.begin(),vpe2.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    
    if(vpe2.back().x-vpe2[0].x>d){
        flag4=false;
    }
    sort(vpe2.begin(),vpe2.end(),[](Point a,Point b){
        return a.y<b.y;
    });
    if(vpe2.back().y-vpe2[0].y>d){
        flag4=false;
    }
    
    
   
    
    return flag1||flag2||flag3||flag4;
    
 
    
}


int main(){

    cin>>N;
    vp.resize(N);
    int x,y;
    for(int i=0;i<N;i++){
        cin>>x>>y;
        vp[i]=Point(x-y,x+y,i);
    }
    
    sort(vp.begin(),vp.end(),[](Point a,Point b){
        return a.x<b.x;
    });
    /*
    for(int i=0;i<vp.size();i++){
        cout<<vp[i].x<<" : "<<vp[i].y<<" ";
    }
    cout<<endl;
     */
    
    
    
    int ng=-1;
    int ok=200050;
    int mid;
    
    while(ok-ng>1){
        mid=(ok+ng)/2;
        if(is_ok(mid)){
            ok=mid;
        }else{
            ng=mid;
        }
    }
    cout<<ok<<endl;
  
    
}
accuracy: 0.8
time_ms: 580
memory_kb: 9076
final_rank: 20

code_snippet: #include <iostream>
#include <vector>

using namespace std;
constexpr int INF = 1 << 30;

void solve() {
    int n;
    cin >> n;

    vector<pair<int, int>> ps(n);
    for (auto& [u, v] : ps) {
        int x, y;
        cin >> x >> y;
        // 45度回転
        u = x + y, v = x - y;
    }

    int ans = INF;
    for (int q = 0; q < 2; ++q) {
        int xl = INF, xr = -INF, yl = INF, yr = -INF;
        for (auto [x, y] : ps) {
            xl = min(xl, x), xr = max(xr, x);
            yl = min(yl, y), yr = max(yr, y);
        }

        int d = 0;
        for (auto [x, y] : ps) {
            // [xl,xl+d]*[yl,yl+d]か[xr-d,xr]*[yr-d,yr]に入れる
            int r = min(max(x - xl, y - yl), max(xr - x, yr - y));
            d = max(d, r);
        }
        ans = min(ans, d);

        // 上下反転
        for (auto& [x, y] : ps) x = -x;
    }

    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3780
final_rank: 3

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> X(N), Y(N);
	for (int i = 0; i < N; ++i) {
		int xt, yt;
		cin >> xt >> yt;
		X[i] = xt + yt;
		Y[i] = xt - yt;
	}
	int xl = *min_element(X.begin(), X.end());
	int xr = *max_element(X.begin(), X.end());
	int yl = *min_element(Y.begin(), Y.end());
	int yr = *max_element(Y.begin(), Y.end());
	int ans1 = min(max(xr - xl, (yr - yl) / 2), max(yr - yl, (xr - xl) / 2));
	int ans2 = 0, ans3 = 0;
	for (int i = 0; i < N; ++i) {
		ans2 = max(ans2, min(max(X[i] - xl, Y[i] - yl), max(xr - X[i], yr - Y[i])));
		ans3 = max(ans3, min(max(X[i] - xl, yr - Y[i]), max(xr - X[i], Y[i] - yl)));
	}
	cout << min({ ans1, ans2, ans3 }) << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3508
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};

void chmin(int &a, int b){
    a = min(a, b);
}

void chmax(int &a, int b){
    a = max(a, b);
}

int n, smax = -INF, smin = INF, tmax = -INF, tmin = INF;
vector<int> s, t;

// 距離x以下で分割できるか
bool check(int x){
    vector<int> gs(n,2), gt(n,2);
    // 45度回転した平面で9つの領域に分類
    for(int i=0;i<n;i++){
        if(min(abs(s[i]-smin),abs(s[i]-smax)) > x) return false;
        else if(abs(s[i]-smax) > x) gs[i] = 0;
        else if(abs(s[i]-smin) > x) gs[i] = 1;
    }
    for(int i=0;i<n;i++){
        if(min(abs(t[i]-tmin),abs(t[i]-tmax)) > x) return false;
        else if(abs(t[i]-tmax) > x) gt[i] = 0;
        else if(abs(t[i]-tmin) > x) gt[i] = 1;
    }
    int cnt[4]{};
    for(int i=0;i<n;i++){
        if(gs[i]==0 && gt[i]==0) cnt[0]++;
        if(gs[i]==0 && gt[i]==1) cnt[1]++;
        if(gs[i]==1 && gt[i]==0) cnt[2]++;
        if(gs[i]==1 && gt[i]==1) cnt[3]++;
    }
    return (cnt[0]+cnt[3]==0 || cnt[1]+cnt[2]==0);
}

int main(){
    cin >> n;
    s.resize(n);
    t.resize(n);
    for(int i=0;i<n;i++){
        int x, y;
        cin >> x >> y;
        s[i] = x+y;
        t[i] = x-y;
        chmax(smax, s[i]); chmin(smin, s[i]);
        chmax(tmax, t[i]); chmin(tmin, t[i]);
    }
    int ok = 1e6, ng = 0;
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 4384
final_rank: 9

code_snippet: #include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int uma,umi,vma,vmi;

int da(int u,int v){
    int l1,l2;
    l1 = max(uma-u,vma-v);
    l2 = max(u-umi,v-vmi);
    return min(l1,l2);
}

int db(int u,int v){
    int l1,l2;
    l1 = max(uma-u,v-vmi);
    l2 = max(u-umi,vma-v);
    return min(l1,l2);
}

int main(){
    int n,x,y,a,b;
    int u[100010],v[100010];
    
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x >> y;
        u[i] = x+y;
        v[i] = x-y;
        if(i == 0){
            uma = u[i];
            umi = u[i];
            vma = v[i];
            vmi = v[i];
        }
        uma = max(uma,u[i]);
        umi = min(umi,u[i]);
        vma = max(vma,v[i]);
        vmi = min(vmi,v[i]);
    }
    
    a = 0;
    b = 0;
    for(int i=0;i<n;i++){
        a = max(a,da(u[i],v[i]));
        b = max(b,db(u[i],v[i]));
    }
    cout << min(a,b) << endl;
    
    return(0);
}
accuracy: 1
time_ms: 40
memory_kb: 3872
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

struct Line {
	int section;
	Line(const int s) : section{ s } {};
	virtual int y(const int x) const = 0;
};

struct Coordinate {
	int x, y;
	int distance_from(const Line& line) const {
		return std::abs(y - line.y(x));
	}
};
struct Line45 : public Line {
	int y(const int x) const override {
		return section + x;
	}
	Line45(const Coordinate& c) : Line{ c.y - c.x } {};
};
struct Line135 : public Line {
	int y(const int x) const override {
		return section - x;
	}
	Line135(const Coordinate& c) : Line{ c.y + c.x } {};
};


int main() {
	int n; std::cin >> n;
	std::vector<Coordinate> facility(n);
	for (auto& f : facility) std::cin >> f.x >> f.y;
	Line45 min_line45(facility.front()), max_line45(facility.front());
	Line135 min_line135(facility.front()), max_line135(facility.front());
	for (const auto& f : facility) {
		Line45 line45(f);
		Line135 line135(f);
		if (line45.section < min_line45.section) {
			min_line45 = line45;
		}
		if (line45.section > max_line45.section) {
			max_line45 = line45;
		}
		if (line135.section < min_line135.section) {
			min_line135 = line135;
		}
		if (line135.section > max_line135.section) {
			max_line135 = line135;
		}
	}
	auto min = 1;
	auto max = 400001;
	while (min < max) {
		auto mid = (min + max) / 2;
		bool can_separate = 
			std::all_of(facility.begin(), facility.end(), [mid, min_line45, max_line45, min_line135, max_line135](const Coordinate& f) {
			return (f.distance_from(min_line45) <= mid && f.distance_from(min_line135) <= mid) ||
				(f.distance_from(max_line45) <= mid && f.distance_from(max_line135) <= mid);
				}) ||
			std::all_of(facility.begin(), facility.end(), [mid, min_line45, max_line45, min_line135, max_line135](const Coordinate& f) {
					return (f.distance_from(max_line45) <= mid && f.distance_from(min_line135) <= mid) ||
						(f.distance_from(min_line45) <= mid && f.distance_from(max_line135) <= mid);
				});
				if (can_separate) {
					max = mid;
				}
				else {
					min = mid + 1;
				}
	}
	std::cout << max << '\n';
}
accuracy: 1
time_ms: 40
memory_kb: 3636
final_rank: 4

code_snippet: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

int INF = 1e9;
long long int MOD = 1e9 + 7;

int x[110000], y[110000];

int dist(int p1, int p2){
	return abs(x[p1] - x[p2]) + abs(y[p1] - y[p2]);
}

int main(){
	int N;
	cin >> N;
	int n1 = INF, n2 = -INF, n3 = INF, n4 = -INF;
	int p1, p2, p3, p4;
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i];
		int m1 = x[i] + y[i], m2 = x[i] - y[i];
		if(m1 < n1){
			n1 = m1;
			p1 = i;
		}
		if(m1 > n2){
			n2 = m1;
			p2 = i;
		}
		if(m2 < n3){
			n3 = m2;
			p3 = i;
		}
		if(m2 > n4){
			n4 = m2;
			p4 = i;
		}
	}
	int ans = INF;
	int S = dist(p3, p4);
	for(int i = 0; i < N; i++){
		S = max(S, min(dist(i, p1), dist(i, p2)));
	}
	ans = min(S, ans);
	S = dist(p1, p2);
	for(int i = 0; i < N; i++){
		S = max(S, min(dist(i, p3), dist(i, p4)));
	}
	ans = min(S, ans);
	S = max(dist(p1, p3), dist(p2, p4));
	for(int i = 0; i < N; i++){
		S = max(S, min(max(dist(i, p1), dist(i, p3)), max(dist(i, p2), dist(i, p4))));
	}
	ans = min(S, ans);
	S = max(dist(p1, p4), dist(p2, p3));
	for(int i = 0; i < N; i++){
		S = max(S, min(max(dist(i, p1), dist(i, p4)), max(dist(i, p2), dist(i, p3))));
	}
	ans = min(S, ans);
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3796
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using P = pair<Int, Int>;
  vector<P> v;
  for(Int i=0;i<n;i++){
    Int x,y;
    cin>>x>>y;
    v.emplace_back(x+y,x-y);
  }
  Int iu=v[0].first,au=v[0].first;
  Int iv=v[0].second,av=v[0].second;
  for(Int i=0;i<n;i++){
    chmin(iu,v[i].first);
    chmax(au,v[i].first);
    chmin(iv,v[i].second);
    chmax(av,v[i].second);
  }
  //cout<<iu<<" "<<au<<":"<<iv<<" "<<av<<endl;
  auto check1=
    [&](Int d)->Int{
      for(Int i=0;i<n;i++){
	if(v[i].first<=iu+d&&v[i].second<=iv+d) continue;
	if(au-d<=v[i].first&&av-d<=v[i].second) continue;
	return 0;
      }
      return 1;
    };
  auto check2=
    [&](Int d)->Int{
      for(Int i=0;i<n;i++){
	if(v[i].first<=iu+d&&av-d<=v[i].second) continue;
	if(au-d<=v[i].first&&v[i].second<=iv+d) continue;
	return 0;
      }
      return 1;
    };
  
  Int l=-1,r=(au-iu)+(av-iv);
  while(l+1<r){
    Int m=(l+r)>>1;
    if(check1(m)||check2(m)) r=m;
    else l=m;
  }
  cout<<r<<endl;
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4936
final_rank: 11

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define Max(a,b) a=max(a,b);
#define Min(a,b) a=min(a,b);
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 100010
ll x[N],y[N],n;
bool F(ll m){
    ll mx=-mod,my=-mod,sx=mod,sy=mod;
    lol(i,n){
	Max(mx,x[i]);Max(my,y[i]);
	Min(sx,x[i]);Min(sy,y[i]);
    }
    if(mx-sx<=m){
	lol(i,n)if(sy+m<y[i]&&y[i]<my-m)return 0;
	return 1;
    }
    if(my-sy<=m){
	lol(i,n)if(sx+m<x[i]&&x[i]<mx-m)return 0;
	return 1;
    }
    ll mw=-mod,mh=-mod,sw=mod,sh=mod;
    lol(i,n){
	if(x[i]>sx+m||y[i]>sy+m){
	    Max(mw,x[i]);Max(mh,y[i]);
	    Min(sw,x[i]);Min(sh,y[i]);
	}
    }
    return (mw-sw<=m&&mh-sh<=m);
}
ll Solve(){
    ll l=0,r=mod,m;
    while(l<r-1){
	m=(l+r)/2;
	if(F(m))r=m;
	else l=m;
    }
    return r;
}
void Flipx(){lol(i,n)x[i]=-x[i];}
void Flipy(){lol(i,n)y[i]=-y[i];}
int main(){
    cin>>n;
    lol(i,n){
	ll a,b;cin>>a>>b;
	x[i]=a+b,y[i]=a-b;
    }
    ll ans=mod;
    Min(ans,Solve());
    Flipx();
    Min(ans,Solve());
    Flipy();
    Min(ans,Solve());
    Flipx();
    Min(ans,Solve());
    cout<<ans<<endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4588
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
typedef pair<int, int> P;
#define X first
#define Y second

struct rcomp{
    bool operator()(const P &a, const P &b){
        return (a.Y != b.Y)? a.Y<b.Y: a.X<b.X;
    }
};

int main(){
    int n;
    cin >> n;
    set<P> pxf;
    set<P, rcomp> pyf;
    for(int i=0; i<n; i++){
        int x,y;
        cin >> x >> y;
        pxf.insert(P(x+y, x-y));
        pyf.insert(P(x+y, x-y));
    }

    //まず最遠点を分ける
    P fp[2];
    if((*pxf.rbegin()).X -(*pxf.begin()).X > (*pyf.rbegin()).Y -(*pyf.begin()).Y){
        fp[0] = *pxf.begin();
        fp[1] = *pxf.rbegin();
    }else{
        fp[0] = *pyf.begin();
        fp[1] = *pyf.rbegin();
    }
    pxf.erase(fp[0]);
    pxf.erase(fp[1]);
    pyf.erase(fp[0]);
    pyf.erase(fp[1]);

    //分割するグループ
    set<P> axf, bxf;
    set<P, rcomp> ayf, byf;
    axf.insert(fp[0]);
    ayf.insert(fp[0]);
    bxf.insert(fp[1]);
    byf.insert(fp[1]);

    while(!pxf.empty()){
        P p1 = *pxf.begin();
        pyf.erase(p1);
        pxf.erase(p1);
        //最も遠い点が、A,B、未処理のどこにあるか判定
        //(ソート済みの最初と最後だけ見ればいい)
        int dax = max(abs((*axf.begin()).X -p1.X), abs((*axf.rbegin()).X -p1.X));
        int day = max(abs((*ayf.begin()).Y -p1.Y), abs((*ayf.rbegin()).Y -p1.Y));
        int dbx = max(abs((*bxf.begin()).X -p1.X), abs((*bxf.rbegin()).X -p1.X));
        int dby = max(abs((*byf.begin()).Y -p1.Y), abs((*byf.rbegin()).Y -p1.Y));
        int dpx = 0;
        int dpy = 0;
        if(!pxf.empty()){
            dpx = max(abs((*pxf.begin()).X -p1.X), abs((*pxf.rbegin()).X -p1.X));
            dpy = max(abs((*pyf.begin()).Y -p1.Y), abs((*pyf.rbegin()).Y -p1.Y));    
        } 
        int da = max(dax, day);
        int db = max(dbx, dby);
        int dp = max(dpx, dpy);

        //Aの場合はBに、Bの場合はAに入れる
        if(da >= max(db, dp)){
            bxf.insert(p1);
            byf.insert(p1);
        }else if(db >= max(da, dp)){
            axf.insert(p1);
            ayf.insert(p1);
        }else{
            //未処理の場合は、未処理最遠点対をA,Bに分けて入れる
            //未処理最遠点を取り出す
            P p2;
            if(dpx > dpy){
                if(abs((*pxf.begin()).X -p1.X) > abs((*pxf.rbegin()).X -p1.X)){
                    p2 = *pxf.begin();     
                }else{
                    p2 = *pxf.rbegin();
                }
            }else{
                if(abs((*pyf.begin()).Y -p1.Y) > abs((*pyf.rbegin()).Y -p1.Y)){
                    p2 = *pyf.begin();     
                }else{
                    p2 = *pyf.rbegin();
                }
            }
            pxf.erase(p2);
            pyf.erase(p2);

            //ロスの少ないほうに入れる
            int dax2 = max(abs((*axf.begin()).X -p2.X), abs((*axf.rbegin()).X -p2.X));
            int day2 = max(abs((*ayf.begin()).Y -p2.Y), abs((*ayf.rbegin()).Y -p2.Y));
            int dbx2 = max(abs((*bxf.begin()).X -p2.X), abs((*bxf.rbegin()).X -p2.X));
            int dby2 = max(abs((*byf.begin()).Y -p2.Y), abs((*byf.rbegin()).Y -p2.Y));
            int da2 = max(dax2, day2);
            int db2 = max(dbx2, dby2);
            if(max(da, db2) > max(db, da2)){
                swap(p1, p2);
            }
            axf.insert(p1);
            ayf.insert(p1);
            bxf.insert(p2);
            byf.insert(p2);
        }
    }
    cout << max(max((*axf.rbegin()).X -(*axf.begin()).X, (*ayf.rbegin()).Y -(*ayf.begin()).Y),
                max((*bxf.rbegin()).X -(*bxf.begin()).X, (*byf.rbegin()).Y -(*byf.begin()).Y) )
            << endl;
    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 12452
final_rank: 18

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100000

enum Type{
	A,
	B,
	Both,
};

struct ADD{
	bool operator<(const struct ADD &arg) const{
		return value < arg.value;
	}
	int value,index;
};

struct SUB{
	bool operator<(const struct SUB &arg) const{
		return value < arg.value;
	}
	int value,index;
};

int N;
ADD info_add[NUM];
SUB info_sub[NUM];
Type type[2][NUM];


bool is_OK(int max_dist){

	for(int i = 0; i < N; i++){
		type[0][i] = Both;
		type[1][i] = Both;
	}

	int num_A;

	type[0][info_add[0].index] = A;
	num_A = 1;

	for(int i = 1; i < N; i++){
		if(info_add[i].value-info_add[0].value > max_dist && info_add[N-1].value - info_add[i].value > max_dist)return false;

		if(info_add[i].value-info_add[0].value > max_dist){
			type[0][info_add[i].index] = B;
		}
		if(info_add[N-1].value-info_add[i].value > max_dist){
			type[0][info_add[i].index] = A;
			num_A++;
		}
	}
	if(num_A == N)return false;

	type[1][info_sub[0].index] = A;
	num_A = 1;

	for(int i = 1; i < N; i++){
		if(info_sub[i].value-info_sub[0].value > max_dist && info_sub[N-1].value - info_sub[i].value > max_dist)return false;

		if(info_sub[i].value-info_sub[0].value > max_dist){
			type[1][info_sub[i].index] = B;
		}
		if(info_sub[N-1].value-info_sub[i].value > max_dist){
			type[1][info_sub[i].index] = A;
			num_A++;
		}
	}
	if(num_A == N)return false;


	int num_both = 0;
	int num_diff = 0;

	for(int i = 0; i < N; i++){
		if(type[0][i] == Both || type[1][i] == Both){

			num_both++;

		}else if(type[0][i] != type[1][i]){
			num_diff++;
		}
	}

	if(num_diff == 0)return true;
	if(num_both+num_diff == N)return true;

	return false;


}

int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){
		info_add[i].index = i;
		info_sub[i].index = i;
	}

	int x,y;
	for(int i = 0; i < N; i++){
		scanf("%d %d",&x,&y);

		info_add[i].value = x+y;
		info_sub[i].value = x-y;
	}
	sort(info_add,info_add+N);
	sort(info_sub,info_sub+N);

	int left = 0,right = 400000, m = (left+right)/2;
	int ans = right;

	while(left <= right){

		if(is_OK(m)){
			ans = m;
			right = m-1;
		}else{
			left = m+1;
		}
		m = (left+right)/2;
	}

	printf("%d\n",ans);

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5568
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int x[100001],y[100001];
int main(){
    int n,xi,yi;
    cin>>n;
    rep(i,n){
        cin>>xi>>yi;
        x[i]=xi+yi;
        y[i]=xi-yi;
    }
    int xmx=*max_element(x,x+n);
    int xmn=*min_element(x,x+n);
    int ymx=*max_element(y,y+n);
    int ymn=*min_element(y,y+n);
    int mx=0,mx2=0;
    rep(i,n){
        mx=max(mx,min(max(xmx-x[i],y[i]-ymn),max(ymx-y[i],x[i]-xmn)));
        mx2=max(mx2,min(max(xmx-x[i],ymx-y[i]),max(y[i]-ymn,x[i]-xmn)));
    }
    cout<<min(mx,mx2)<<endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3892
final_rank: 7

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

struct point {
	LL x, y;
	//0=どちらも 1=A 2=B 3=矛盾
	int idx;
	int idy;
	point(LL x, LL y)
		:x(x), y(y), idx(), idy() {}
};

int N;
vector<point>vec;

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; ++i) {
		LL x, y;
		cin >> x >> y;
		vec.push_back(point(x + y, x - y));
	}
	int lo = 0, hi = 222222;
	while (lo + 1 < hi) {
		int mid = (lo + hi) / 2;
		vector<point>tmp = vec;
		sort(tmp.begin(), tmp.end(), [](const point&p1, const point&p2) {
			return p1.x < p2.x;
		});
		LL fx = tmp.front().x;
		LL bx = tmp.back().x;
		//[fx+mid+1,INF]をAにする
		//[-INF,bx-mid-1]をBにする
		for (int i = 0; i < N; ++i) {
			if (fx + mid + 1 <= tmp[i].x) {
				tmp[i].idx += 1;
			}
			if (tmp[i].x <= bx - mid - 1) {
				tmp[i].idx += 2;
			}
		}
		sort(tmp.begin(), tmp.end(), [](const point&p1, const point&p2) {
			return p1.y < p2.y;
		});
		LL fy = tmp.front().y;
		LL by = tmp.back().y;
		//[fy+mid+1,INF]をAにする
		//[-INF,by-mid-1]をBにする
		for (int i = 0; i < N; ++i) {
			if (fy + mid + 1 <= tmp[i].y) {
				tmp[i].idy += 1;
			}
			if (tmp[i].y <= by - mid - 1) {
				tmp[i].idy += 2;
			}
		}
		//チェックする
		bool oneflag = true;
		bool twoflag = true;
		const auto convbit = [](int id) {
			if (id == 0)return 0;
			if (id == 1)return 2;
			if (id == 2)return 1;
			if (id == 3)return 3;
		};
		for (int i = 0; i < N; ++i) {
			if ((tmp[i].idx | tmp[i].idy) == 3) {
				oneflag = false;
			}
			if ((tmp[i].idx | convbit(tmp[i].idy)) == 3) {
				twoflag = false;
			}
		}
		bool flag = (oneflag || twoflag);
		if (!flag) {
			lo = mid;
		}
		else {
			hi = mid;
		}
	}
	cout << hi << endl;
	return 0;
}
accuracy: 0.8
time_ms: 250
memory_kb: 7364
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> P;
const int inf = 1e6;
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = 1;i <= n;i++)

int used[100000];

int calc(int k, vector<P> x, int f, int a, int b){
	int n = x.size();
	for(int i = 0;i < n;i++){
		if(x[0].fi+k < x[i].fi){
			int u = x[i].se;
			if(used[u] == b || x[i].fi+k < x[n-1].fi)return 0;
			if(f)used[u] = a;
		}
	}
	for(int i = n-1;i >= 0;i--){
		if(x[i].fi+k < x[n-1].fi){
			int u = x[i].se;
			if(used[u] == a)return 0;
			if(f)used[u] = b;
		}
	}
	return 1;
}

vector<P> x, y;
int solve(int k){
	int t[3] = {}; 
	t[0] = calc(k, x, 1, 1, 2);
	t[1] = calc(k, y, 0, 1, 2);
	t[2] = calc(k, y, 0, 2, 1);
	if(t[0] == 0)return 0;
	if(t[1] || t[2])return 1;
	return 0;
}

int main(){
	int n, a, b;
	
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d%d", &a, &b);
		x.push_back(P(a+b, i));
		y.push_back(P(b-a, i));
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	
	
	int lb = 0, ub = inf;
	while(ub-lb > 1){
		fill(used, used+100000, 0);
		int mid = (lb+ub)/2;
		int res = solve(mid);
		if(res)ub = mid;
		else lb = mid;
	}
	
	printf("%d\n", ub);
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5760
final_rank: 15