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

#include <bits/stdc++.h>
#define ll long long int
#define db long double
#define ull unsigned long long int
// #define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define all(a) a.begin(), a.end()
#define Nmax 1000005
// #define INF 10000000000000
#define MOD 1000000007
#define MAXN 200005

using namespace std;

ll mod = 1e9 + 7;

ll expo(ll base, ll exponent, ll mod) {
  ll ans = 1;
  while (exponent != 0) {
    if (exponent & 1)
      ans = (1LL * ans * base) % mod;
    base = (1LL * base * base) % mod;
    exponent >>= 1;
  }
  return ans % mod;
}

const ll M = 3000006;
ll f[M], inv[M];

void compute() {
  f[0] = 1;
  rep(i, 1, M - 1) { f[i] = (1LL * i * f[i - 1]) % mod; }
  inv[M - 1] = expo(f[M - 1], mod - 2, mod);
  for (ll i = M - 2; i >= 0; i--) {
    inv[i] = (1LL * (i + 1) * inv[i + 1]) % mod;
  }
}
ll C(ll n, ll r) {
  return (1LL * ((1LL * f[n] * inv[r]) % mod) * inv[n - r]) % mod;
}

bool mysort(pair<ll, ll> &p1, pair<ll, ll> &p2) {
  return p1.F + p1.S < p2.F + p2.S;
}

bool sorter(pair<ll, ll> &p1, pair<ll, ll> &p2) {
  return (mod - p1.F + mod - p1.S) < (mod - p2.S + mod - p2.F);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // compute();
  int tests = 1;
  // cin>>tests;
  while (tests--) {
    ll i, j, n;
    cin >> n;
    vector<pair<ll, ll>> v;
    ll mx = LLONG_MIN, mn = LLONG_MAX, mx1 = LLONG_MIN, mx2 = LLONG_MIN;
    rep(i, 1, n) {
      ll x, y;
      cin >> x >> y;
      mx = max(mx, x + y);
      mn = min(mn, x + y);
      mx1 = max(mx1, x - y);
      mx2 = max(mx2, y - x);
    }
    ll ans = LLONG_MIN;
    ans = max(ans, mx - mn);
    ans = max(ans, mx1 + mx2);
    cout << ans;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define db long double
#define ull unsigned long long int
// #define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define all(a) a.begin(), a.end()
#define Nmax 1000005
// #define INF 10000000000000
#define MOD 1000000007
#define MAXN 200005

using namespace std;

ll mod = 1e9 + 7;

ll expo(ll base, ll exponent, ll mod) {
  ll ans = 1;
  while (exponent != 0) {
    if (exponent & 1)
      ans = (1LL * ans * base) % mod;
    base = (1LL * base * base) % mod;
    exponent >>= 1;
  }
  return ans % mod;
}

const ll M = 3000006;
ll f[M], inv[M];

void compute() {
  f[0] = 1;
  rep(i, 1, M - 1) { f[i] = (1LL * i * f[i - 1]) % mod; }
  inv[M - 1] = expo(f[M - 1], mod - 2, mod);
  for (ll i = M - 2; i >= 0; i--) {
    inv[i] = (1LL * (i + 1) * inv[i + 1]) % mod;
  }
}
ll C(ll n, ll r) {
  return (1LL * ((1LL * f[n] * inv[r]) % mod) * inv[n - r]) % mod;
}

bool mysort(pair<ll, ll> p1, pair<ll, ll> p2) {
  return p1.F + p1.S < p2.F + p2.S;
}

bool sort2(pair<ll, ll> p1, pair<ll, ll> p2) {
  if (p1.S < p2.S)
    return true;
  else
    return p1.F < p2.F;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // compute();
  int tests = 1;
  // cin>>tests;
  while (tests--) {
    ll i, j, n;
    cin >> n;
    vector<pair<ll, ll>> v;
    rep(i, 1, n) {
      ll x, y;
      cin >> x >> y;
      v.pb({x, y});
    }
    sort(all(v), mysort);
    ll ans = abs(v[0].F - v[n - 1].F) + abs(v[0].S - v[n - 1].S);
    sort(all(v));
    ans = max(ans, abs(v[0].F - v[n - 1].F) + abs(v[0].S - v[n - 1].S));
    sort(all(v), sort2);
    ans = max(ans, abs(v[0].F - v[n - 1].F) + abs(v[0].S - v[n - 1].S));
    cout << ans;
  }

  return 0;
}