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

// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>; #define Find order_of_key #define at
// find_by_order
#define x first
#define y second
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ulll unsigned __int128
#define pii pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define gu getchar_unlocked()
#define pu putchar_unlocked()
#define all(x) x.begin(), x.end()
#define endl '\\n'
const int mx = 200010;
int n;
pii p[mx];
int main() {
  cin >> n;
  ll a = -1e18, b = -1e18, c = -1e18, d = -1e18;
  for (int i = 0; i < n; i++) {
    cin >> p[i].x >> p[i].y;
    a = max(a, p[i].x + p[i].y);
    b = max(b, p[i].x - p[i].y);
    c = max(c, -p[i].x + p[i].y);
    d = max(d, -p[i].x - p[i].y);
  }
  ll an = -1;
  for (int i = 0; i < n; i++) {
    an = max(an, a + (-p[i].x - p[i].y));
    an = max(an, b + (-p[i].x + p[i].y));
    an = max(an, c + (+p[i].x - p[i].y));
    an = max(an, d + (+p[i].x + p[i].y));
  }
  cout << an << endl;
  return 0;
}

Error: TLE

Fixed submission:

// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>; #define Find order_of_key #define at
// find_by_order
#define x first
#define y second
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ulll unsigned __int128
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define gu getchar_unlocked()
#define pu putchar_unlocked()
#define all(x) x.begin(), x.end()
#define endl '\\n'

#define sq(a) ((a) * (a))
struct point {
  ll x, y;
  bool operator<(const point &p) const { return x == p.x ? y < p.y : x < p.x; }
};
ll dist(point &p, point &q) { return abs(p.x - q.x) + abs(p.y - q.y); }
vector<point> p;
ll solve(int l, int r) {
  if (r - l <= 3) {
    ll ret = 0;
    for (int i = l; i <= r; i++)
      for (int j = i + 1; j <= r; j++)
        ret = max(ret, dist(p[i], p[j]));
    return ret;
  }
  int mid = l + r >> 1;
  ll d = max(solve(l, mid), solve(mid + 1, r));

  vector<point> t;
  for (int i = l; i <= r; i++)
    if (abs(p[mid].x - p[i].x) <= d)
      t.push_back({p[i].y, p[i].x});

  sort(t.begin(), t.end());
  for (int i = 0; i < t.size(); i++) {
    for (int j = i + 1; j < t.size(); j++)
      d = max(d, dist(t[i], t[j]));
  }
  return d;
}
ll closestPair() {
  sort(p.begin(), p.end());
  return solve(0, p.size() - 1);
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    p.push_back({x, y});
  }
  cout << closestPair() << endl;
  return 0;
}