Problem p02556 (C++) — buggy submission, verdict: Runtime Error

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

#define M 1000000007
#define FOR(i, s, n) for (ll i = (s); i < (n); ++i)
#define FORALL(i, n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back((x))
#define vll vector<ll>
#define all(x) x.begin(), x.end()
#define print(x) cout << x << endl
#define debug print("reaching\\n")
#define mll map<ll, ll>
#define lsb(i) i & (-i)
#define printv(x)                                                              \\
  FORALL(i, x.size()) { cout << x[i] << ' '; }                                 \\
  cout << endl;
#define printm(m)                                                              \\
  for (auto i : m) {                                                           \\
    cout << i.ff << ' ' << i.ss << endl;                                       \\
  };

template <typename T> T extGcd(T a, T b, T &x, T &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    int g = extGcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
  }
}

template <typename T> T modInv(T a, T m) {
  T x, y;
  extGcd(a, m, x, y);
  return (x % m + m) % m;
}
// vector<map<ll,ll>> m(2);
long long binpow(long long a, long long b) {
  a %= MOD;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

bool com1(pll a, pll b) {
  ll n = a.first + a.second;
  ll m = b.first + b.second;
  if (n == m)
    return 0;
  return n > m;
}
bool com2(pll a, pll b) {
  ll n = -a.first + a.second;
  ll m = -b.first + b.second;
  if (n == m)
    return 0;
  return n > m;
}
bool com3(pll a, pll b) {
  ll n = a.first - a.second;
  ll m = b.first - b.second;
  if (n == m)
    return 0;
  return n > m;
}
int main() {
  fast;
  // cin.tie(0);
  // cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif

  int t = 1;
  // cin>>t;
  ll tot = t;
  while (t--) {
    ll n;
    cin >> n;
    vector<pll> v;
    FORALL(i, n) {
      ll x, y;
      cin >> x >> y;
      v.push_back({x, y});
    }
    sort(all(v), com1);
    ll dist =
        abs(v[0].first - v[n - 1].first) + abs(v[n - 1].second - v[0].second);

    sort(all(v), com2);
    dist = max(dist, abs(v[0].first - v[n - 1].first) +
                         abs(v[n - 1].second - v[0].second));
    sort(all(v), com3);
    dist = max(dist, abs(v[0].first - v[n - 1].first) +
                         abs(v[n - 1].second - v[0].second));
    print(dist);
  }

  return 0;
}

Error: 0

Fixed submission:

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

#define M 1000000007
#define FOR(i, s, n) for (ll i = (s); i < (n); ++i)
#define FORALL(i, n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back((x))
#define vll vector<ll>
#define all(x) x.begin(), x.end()
#define print(x) cout << x << endl
#define debug print("reaching\\n")
#define mll map<ll, ll>
#define lsb(i) i & (-i)
#define printv(x)                                                              \\
  FORALL(i, x.size()) { cout << x[i] << ' '; }                                 \\
  cout << endl;
#define printm(m)                                                              \\
  for (auto i : m) {                                                           \\
    cout << i.ff << ' ' << i.ss << endl;                                       \\
  };

template <typename T> T extGcd(T a, T b, T &x, T &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    int g = extGcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
  }
}

template <typename T> T modInv(T a, T m) {
  T x, y;
  extGcd(a, m, x, y);
  return (x % m + m) % m;
}
// vector<map<ll,ll>> m(2);
long long binpow(long long a, long long b) {
  a %= MOD;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

bool com(pll a, pll b) {
  if (a.first == b.first) {
    return a.second <= b.second;
  }
  return a.first < b.first;
}

int main() {
  fast;
  // cin.tie(0);
  // cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif

  int t = 1;
  // cin>>t;
  ll tot = t;
  while (t--) {
    ll n;
    cin >> n;
    vector<pll> v;
    FORALL(i, n) {
      ll x, y;
      cin >> x >> y;
      v.push_back({x, y});
    }
    sort(all(v), com);
    pll low = v[0];
    ll dist = 0;
    FORALL(i, n) {
      dist = max(dist,
                 abs(low.first - v[i].first) + abs(low.second - v[i].second));
    }
    print(dist);
  }

  return 0;
}