Language: C++


#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    bool operator==(const mint a){
        return (x == a.x);
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// 2項係数を求める
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

//nが非常に大きく、aが小さい場合
mint choose(int n, int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

ll pow_mod(ll n, ll k, ll m){
    
    if (k == 0){
        return 1;
    }
    else if(k % 2 == 1){
        return pow_mod(n, k - 1, m) * n % m;
    }
    else{
        ll t = pow_mod(n, k / 2, m);
        return t * t % m;
    }
}

ll factorial(ll a){
    if (a == 1) return 1;
    // 階乗を求める場合、数が大きすぎる場合があるので毎回MODをとる。
    return (a*factorial(a-1)) % MOD;
}

bool comp(pair<ll,ll> a, pair<ll,ll> b){
    return a.second < b.second;
}

bool comp2(pair<ll,ll> a, pair<ll,ll> b){
    return a.second > b.second;
}

ll dist(ll x, ll y, ll x2, ll y2){
    return abs(x-x2)+abs(y-y2);
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<pair<ll,ll>> xy(N);
    vector<pair<ll,ll>> xy2, xy3, xy4;
    //vector<ll> x(N), y(N);
    rep(i,N){
        cin >> xy[i].first >> xy[i].second;
        //xy2[i].first = xy[i].first;
        //xy2[i].second = xy[i].second;
        //x[i] = xy[i].first;
        //y[i] = xy[i].second;
    }
    xy2 = xy3 = xy4 = xy;

    sort(xy.begin(), xy.end());
    sort(xy2.rbegin(), xy2.rend());
    sort(xy3.begin(), xy3.end(), comp);
    sort(xy4.begin(), xy4.end(), comp2);

    ll ans = 0;
    int m = 10000;
    int n = 10000;
    rep(i,min(N,m)){
        rep(j,min(N,m)){
            ans = max(ans, dist(xy[i].first, xy[i].second, xy2[j].first,xy2[j].second));
            ans = max(ans, dist(xy[i].first, xy[i].second, xy4[j].first,xy4[j].second));
            ans = max(ans, dist(xy3[i].first, xy3[i].second, xy4[j].first,xy4[j].second));
            ans = max(ans, dist(xy3[i].first, xy3[i].second, xy2[j].first,xy2[j].second));
            if (N > 15000){
                int index = n + m + i;
                int indexj = n + m + j;
                if (index < N && indexj < N){
                    ans = max(ans, dist(xy[index].first, xy[index].second, xy2[indexj].first,xy2[indexj].second));
                    ans = max(ans, dist(xy3[index].first, xy3[index].second, xy4[indexj].first,xy4[indexj].second));
                    ans = max(ans, dist(xy3[index].first, xy3[indexi].second, xy2[j].first,xy2[j].second));
                    ns = max(ans, dist(xy3[indexi].first, xy3[index].second, xy4[j].first,xy4[j].second));
                }
            }

        }
    }
/*
    rep(i,min(N,m)){
        rep(j,min(N,m)){
            ans = max(ans, dist(xy3[i].first, xy3[i].second, xy2[j].first,xy2[j].second));
            ans = max(ans, dist(xy3[i].first, xy3[i].second, xy4[j].first,xy4[j].second));
        }
    }
*/
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:162:63: error: 'indexi' was not declared in this scope; did you mean 'indexj'?
  162 |                     ans = max(ans, dist(xy3[index].first, xy3[indexi].second, xy2[j].first,xy2[j].second));
      |                                                               ^~~~~~
      |                                                               indexj
a.cc:163:21: error: 'ns' was not declared in this scope; did you mean 'n'?
  163 |                     ns = max(ans, dist(xy3[indexi].first, xy3[index].second, xy4[j].first,xy4[j].second));
      |                     ^~
      |                     n