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

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#define lli long long int
#define deb1(x) cout << #x << " :: " << x << "\\n";
#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define deb2(x, y)                                                             \\
  cout << #x << " :: " << x << "\\t" << #y << " :: " << y << "\\n";
#define deb3(x, y, z)                                                          \\
  cout << #x << " :: " << x << "\\t" << #y << " :: " << y << "\\t" << #z         \\
       << " :: " << z << "\\n";
#define deb(v)                                                                 \\
  for (lli i = 0; i < v.size(); i++) {                                         \\
    cout << v[i];                                                              \\
    (i == v.size() - 1) ? cout << "\\n" : cout << " ";                          \\
  }
#define all(a) a.begin(), a.end()
#define ll long long
using namespace std;
#define f first
#define sd second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(x) (ll) x.size()
#define vl vector<lli>
#define pii pair<lli, lli>
lli mod = 1e9 + 7;
using namespace std;
lli t, n, u, x, y, m;
const lli N = 100001;
int main() {
  fast t = 1;
  // cin>>t;
  while (t--) {
    cin >> n;
    vl a(n), b(n);
    lli ans = 0;
    for (int i = 0; i < n; ++i) {
      cin >> x >> y;
      a[i] = x + y;
      b[i] = x - y;
    }
    sort(all(b));
    sort(all(a));
    ans = max(abs(a[0] - a[n - 1]), abs(b[0] - b[n - 1]));
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#define lli long long int
#define deb1(x) cout << #x << " :: " << x << "\\n";
#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define deb2(x, y)                                                             \\
  cout << #x << " :: " << x << "\\t" << #y << " :: " << y << "\\n";
#define deb3(x, y, z)                                                          \\
  cout << #x << " :: " << x << "\\t" << #y << " :: " << y << "\\t" << #z         \\
       << " :: " << z << "\\n";
#define deb(v)                                                                 \\
  for (lli i = 0; i < v.size(); i++) {                                         \\
    cout << v[i];                                                              \\
    (i == v.size() - 1) ? cout << "\\n" : cout << " ";                          \\
  }
#define all(a) a.begin(), a.end()
#define ll long long
using namespace std;
#define f first
#define sd second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(x) (ll) x.size()
#define vl vector<lli>
#define pii pair<lli, lli>
lli mod = 1e9 + 7;
using namespace std;
lli t, n, u, x, y, m;
const lli N = 100001;
int main() {
  fast t = 1;
  // cin>>t;
  while (t--) {
    cin >> n;
    set<pii> s;
    lli ans = 0;
    for (int i = 0; i < n; ++i) {
      cin >> x >> y;
      for (auto j : s)
        ans = max(ans, abs(x - j.f) + abs(y - j.sd));
      s.insert({x, y});
    }
    cout << ans << endl;
  }
}