Problem p02556 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i, n) for (auto &i : n)

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} init_;

#ifdef DEBUG
template <class T, class N> void verr(const T &a, const N &n) {
  rep(i, n) cerr << a[i] << " ";
  cerr << "\n" << flush;
}
ll dbgt = 1;
void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template <class H, class... T> void err(H &&h, T &&...t) {
  cerr << h << (sizeof...(t) ? " " : "\n") << flush;
  if (sizeof...(t) > 0)
    err(forward<T>(t)...);
}
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
struct p {
  ll x, y;
  p() {}
  p(ll x, ll y) : x(x), y(y) {}
};

ll dist(p a, p b) { return max(abs(a.x - b.x), abs(a.y - b.y)); }

int main() {
  ll N;
  cin >> N;
  vc<p> P(N);
  rep(i, N) cin >> P[i].x >> P[i].y;

  vc<p> Q(N);
  rep(i, N) Q[i].x = P[i].x - P[i].y, Q[i].y = P[i].x + P[i].y;

  ll ans = 0;

  sort(all(Q), [](p a, p b) { return a.x < a.y; });

  p xmin = Q.front(), xmax = Q.back();
  chmax(ans, dist(xmax, xmin));

  sort(all(Q), [](p a, p b) { return a.y < b.y; });

  p ymin = Q.front(), ymax = Q.back();
  chmax(ans, dist(ymax, ymin));

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i, n) for (auto &i : n)

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} init_;

#ifdef DEBUG
template <class T, class N> void verr(const T &a, const N &n) {
  rep(i, n) cerr << a[i] << " ";
  cerr << "\n" << flush;
}
ll dbgt = 1;
void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template <class H, class... T> void err(H &&h, T &&...t) {
  cerr << h << (sizeof...(t) ? " " : "\n") << flush;
  if (sizeof...(t) > 0)
    err(forward<T>(t)...);
}
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
struct p {
  ll x, y;
  p() {}
  p(ll x, ll y) : x(x), y(y) {}
};

ll dist(p a, p b) { return max(abs(a.x - b.x), abs(a.y - b.y)); }

int main() {
  ll N;
  cin >> N;
  vc<p> P(N);
  rep(i, N) cin >> P[i].x >> P[i].y;

  vc<p> Q(N);
  rep(i, N) Q[i].x = P[i].x - P[i].y, Q[i].y = P[i].x + P[i].y;

  ll ans = 0;

  sort(all(Q), [](p a, p b) { return a.x < b.x; });

  p xmin = Q.front(), xmax = Q.back();
  chmax(ans, dist(xmax, xmin));

  sort(all(Q), [](p a, p b) { return a.y < b.y; });

  p ymin = Q.front(), ymax = Q.back();
  chmax(ans, dist(ymax, ymin));

  cout << ans << endl;
}