Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
/*
struct UnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> size;

    //こいつがいわゆるコンストラクタ
    //初期化している
    UnionFind(int N) : par(N),rank(N),size(N){
        for(int i=0;i<N;i++){
            par[i]=i;
            size[i]=1;
            rank[i]=0;
        }
    }

    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }


    void unite(int x, int y){
        int rx,ry;
        rx = find(x);
        ry = find(y);
        if(rx == ry){
            return;
        }
        else{
            if(rank[rx]<rank[ry]){
                par[rx]=ry;
                size[ry]+=size[rx];
            }
            else{
                par[ry]=rx;
                size[rx]+=size[ry];
                if(rank[rx]==rank[ry]){
                    rank[rx]++;
                }
            }
        }
    }


    bool same(int x,int y){
        return find(x) == find(y);
    }
};
*/
ll myabs(ll k) {
  if (k < 0) {
    k = 0 - k;
  }
  return k;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> x(N);
  vector<ll> y(N);
  for (ll i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  ll tmpa = 0;
  ll tmpb = 0;
  ll tmpc = 0;
  ll tmpd = 0;
  // ll ans = 0;
  vector<ll> sa(N);
  vector<ll> wa(N);
  for (ll i = 0; i < N; i++) {
    sa.at(i) = x.at(i) - y.at(i);
    wa.at(i) = x.at(i) + y.at(i);
  }
  sort(sa.begin(), sa.end());
  tmpa = sa.at(0);
  reverse(sa.begin(), sa.end());
  tmpb = sa.at(0);
  tmpb = tmpb - tmpa;
  sort(wa.begin(), wa.end());
  tmpc = wa.at(0);
  reverse(wa.begin(), wa.end());
  tmpd = wa.at(0);
  tmpd = tmpd - tmpc;
  if (tmpd > tmpb) {
    cout << tmpd << endl;
  } else {
    cout << tmpb << endl;
  }

  // for(ll i=0;i<N-1;i++){
  //     for(ll j=i+1;j<N;j++){
  //         tmpx = myabs(x.at(i)-x.at(j));
  //         tmpy = myabs(y.at(i)-y.at(j));
  //         tmp = tmpx + tmpy;
  //         if(ans<tmp){
  //             ans=tmp;
  //         }
  //     }
  // }
  // cout<<ans<<endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
/*
struct UnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> size;

    //こいつがいわゆるコンストラクタ
    //初期化している
    UnionFind(int N) : par(N),rank(N),size(N){
        for(int i=0;i<N;i++){
            par[i]=i;
            size[i]=1;
            rank[i]=0;
        }
    }

    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }


    void unite(int x, int y){
        int rx,ry;
        rx = find(x);
        ry = find(y);
        if(rx == ry){
            return;
        }
        else{
            if(rank[rx]<rank[ry]){
                par[rx]=ry;
                size[ry]+=size[rx];
            }
            else{
                par[ry]=rx;
                size[rx]+=size[ry];
                if(rank[rx]==rank[ry]){
                    rank[rx]++;
                }
            }
        }
    }


    bool same(int x,int y){
        return find(x) == find(y);
    }
};
*/
ll myabs(ll k) {
  if (k < 0) {
    k = 0 - k;
  }
  return k;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> x(N);
  vector<ll> y(N);
  for (ll i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  ll tmpx = 0;
  ll tmpy = 0;
  ll tmp = 0;
  ll ans = 0;
  for (ll i = 0; i < N - 1; i++) {
    for (ll j = i + 1; j < N; j++) {
      tmpx = myabs(x.at(i) - x.at(j));
      tmpy = myabs(y.at(i) - y.at(j));
      tmp = tmpx + tmpy;
      if (ans < tmp) {
        ans = tmp;
      }
    }
  }
  cout << ans << endl;
}