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

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;
const ll lnf = 1ll << 60;

int main() {
  ll n;
  cin >> n;
  vector<ll> x(n);
  vector<ll> y(n);
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) {
    cin >> x[i] >> y[i];
    a[i] = abs(x[i] - 1) + abs(y[i] - 1);
    b[i] = abs(x[i] - 1e9) + abs(y[i] - 1);
  }
  sortt(a);
  sortt(b);
  ll ans = 0;
  chmax(ans, a[n - 1] - a[0]);
  chmax(ans, b[n - 1] - b[0]);
  cout << ans << endl;
}

Error: 0

Fixed submission:

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;
const ll lnf = 1ll << 60;

int main() {
  ll n;
  cin >> n;
  vector<ll> x(n);
  vector<ll> y(n);
  rep(i, n) { cin >> x[i] >> y[i]; }
  vector<ll> x1 = x;
  vector<ll> y1 = y;
  sortt(x1);
  sortt(y1);
  ll xm = x1[n / 2];
  ll ym = y1[n / 2];
  vector<pll> a;
  vector<pll> b;
  vector<pll> c;
  vector<pll> d;
  rep(i, n) {
    if (x[i] - xm >= 0 && y[i] - ym >= 0)
      a.push_back(pll(abs(x[i] - xm) + abs(y[i] - ym), i));
    if (x[i] - xm <= 0 && y[i] - ym >= 0)
      b.push_back(pll(abs(x[i] - xm) + abs(y[i] - ym), i));
    if (x[i] - xm >= 0 && y[i] - ym <= 0)
      c.push_back(pll(abs(x[i] - xm) + abs(y[i] - ym), i));
    if (x[i] - xm <= 0 && y[i] - ym <= 0)
      d.push_back(pll(abs(x[i] - xm) + abs(y[i] - ym), i));
  }
  rsort(a);
  rsort(b);
  rsort(c);
  rsort(d);
  ll ans = 0;
  set<ll> st;
  st.insert(a[0].se);
  st.insert(b[0].se);
  st.insert(c[0].se);
  st.insert(d[0].se);
  for (auto i : st) {
    for (auto j : st) {
      chmax(ans, abs(x[i] - x[j]) + abs(y[i] - y[j]));
    }
  }
  cout << ans << endl;
}