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

/**
 *	created: 14.09.2020 00:11:15
 **/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int, int>;
// #define endl '\\n'
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> T pow(T a, ll n) {
  T r(1);
  while (n) {
    if (n & 1)
      r *= a;
    a *= a;
    n >>= 1;
  }
  return r;
}
struct faster_io {
  faster_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
  }
} faster_io_;

signed main() {
  int n;
  cin >> n;
  vector<int> z, w;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    int Z = a + b, W = a - b;
    z.push_back(Z);
    w.push_back(W);
  }
  sort(all(z));
  sort(all(w));
  cout << max(z[n - 1] - z[0], w[n - 1] - w[0]) << endl;
  return 0;
}

Error: WA

Fixed submission:

/**
 *	created: 13.09.2020 21:29:22
 **/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int, int>;
// #define endl '\\n'
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> T pow(T a, ll n) {
  T r(1);
  while (n) {
    if (n & 1)
      r *= a;
    a *= a;
    n >>= 1;
  }
  return r;
}
struct faster_io {
  faster_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
  }
} faster_io_;

bool com(P a, P b) {
  if (a.first + a.second > b.first + b.second)
    return a > b;
  else
    return b > a;
}

signed main() {
  vector<P> d1, d2, d3, d4;
  // d1.push_back(P(0,0));
  // d2.push_back(P(0,0));
  // d3.push_back(P(0,0));
  // d4.push_back(P(0,0));
  int n;
  cin >> n;
  bool g = false;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0)
      g = true;
    if (a >= 0 && b > 0)
      d1.push_back(P(a, b));
    if (a < 0 && b > 0)
      d2.push_back(P(-a, b));
    if (a < 0 && b < 0)
      d3.push_back(P(-a, -b));
    if (a >= 0 && b < 0)
      d4.push_back(P(a, -b));
  }
  sort(rall(d1), com);
  sort(rall(d2), com);
  sort(rall(d3), com);
  sort(rall(d4), com);
  int ans = 0;
  vector<P> v;
  if (d1.size() != 0) {
    v.push_back(d1[0]);
    v.push_back(d1[d1.size() - 1]);
  }
  if (d2.size() != 0) {
    v.push_back(P(-d2[0].first, d2[0].second));
    v.push_back(P(-d2[d2.size() - 1].first, d2[d2.size() - 1].second));
  }
  if (d3.size() != 0) {
    v.push_back(P(-d3[0].first, -d3[0].second));
    v.push_back(P(-d3[d3.size() - 1].first, -d3[d3.size() - 1].second));
  }
  if (d4.size() != 0) {
    v.push_back(P(d4[0].first, -d4[0].second));
    v.push_back(P(d4[d4.size() - 1].first, -d4[d4.size() - 1].second));
  }
  sort(all(v));
  v.erase(unique(all(v)), v.end());

  rep(i, 8) rep(j, i) {
    if (!g) {
      if (v[i] == P(0, 0) || v[j] == P(0, 0))
        continue;
    }
    int d = abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second);
    chmax(ans, d);
  }

  cout << ans << endl;
  return 0;
}