Problem p02556 (C++)

Buggy submission (status: Runtime Error):
/*input
2
1 1
1 1
*/

// Nihesh Anderson - knandy

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set; // find_by_order, order_of_key
ll MOD = 1000000007;

#define endl '\n'
#define fast_cin()                                                             \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md) {
  if (n == 0) {
    return 1;
  } else {
    ll res = power(a, n / 2, md);
    res = (res * res) % md;
    if (n % 2 != 0) {
      res = (res * a) % md;
    }
    return res;
  }
}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll *a, ll *b) { shuffle(a, b, grndm); }

const ll MX = 1000000000;

int main() {
  fast_cin();
  // freopen("input.in","r",stdin);
  // freopen("output.out","w",stdout);
  ll n;
  cin >> n;
  vector<ll> v[4];
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    v[0].push_back(y - 1 + x - 1);
    v[1].push_back(x - 1 + MX - y);
    v[2].push_back(MX - x + y - 1);
    v[3].push_back(MX - x + MX - y);
  }
  for (ll i = 0; i < n; i++) {
    sort(v[i].begin(), v[i].end());
  }
  ll ans = 0;
  for (ll i = 0; i < 4; i++) {
    ans = max(ans, v[i][n - 1] - v[i][0]);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
/*input
2
1 1
1 1
*/

// Nihesh Anderson - knandy

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set; // find_by_order, order_of_key
ll MOD = 1000000007;

#define endl '\n'
#define fast_cin()                                                             \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md) {
  if (n == 0) {
    return 1;
  } else {
    ll res = power(a, n / 2, md);
    res = (res * res) % md;
    if (n % 2 != 0) {
      res = (res * a) % md;
    }
    return res;
  }
}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll *a, ll *b) { shuffle(a, b, grndm); }

const ll MX = 1000000000;

int main() {
  fast_cin();
  // freopen("input.in","r",stdin);
  // freopen("output.out","w",stdout);
  ll n;
  cin >> n;
  vector<ll> v[4];
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    v[0].push_back(y - 1 + x - 1);
    v[1].push_back(x - 1 + MX - y);
    v[2].push_back(MX - x + y - 1);
    v[3].push_back(MX - x + MX - y);
  }
  for (ll i = 0; i < 4; i++) {
    sort(v[i].begin(), v[i].end());
  }
  ll ans = 0;
  for (ll i = 0; i < 4; i++) {
    ans = max(ans, v[i][n - 1] - v[i][0]);
  }
  cout << ans << endl;
  return 0;
}