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

/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define vii vector<int>
#define pii pair<int, int>
#define fi first
#define all(a) (a).begin(), (a).end()
#define si(x) (int)((x).size())
#define debug(x)                                                               \\
  cout << #x << " is " << (x) << endl;                                         \\
  cout.flush();
#define se second
#define endl '\\n'
#define f(i, a, b) for (int i = a; i < b; i++)
#define mem(a, x) memset(a, x, sizeof(a))
#define hs                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

// const ll mod=998244353;
const int mod = 1000000000 + 7;
const int N = 1000000 + 6;
#define M_PI 3.14159265358979323846

// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
// int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
// int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
// int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
// int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x)                                                                 \\
  {                                                                            \\
    ++recur_depth;                                                             \\
    auto x_ = x;                                                               \\
    --recur_depth;                                                             \\
    cerr << string(recur_depth, '\\t') << "\\e[91m" << __func__ << ":"           \\
         << __LINE__ << "\\t" << #x << " = " << x_ << "\\e[39m" << endl;         \\
  }
#else
#define dbg(x)
#endif
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream &>::type
operator<<(Ostream &os, const Cont &v) {
  os << "[";
  for (auto &x : v) {
    os << x << ", ";
  }
  return os << "]";
}
template <typename Ostream, typename... Ts>
Ostream &operator<<(Ostream &os, const pair<Ts...> &p) {
  return os << "{" << p.first << ", " << p.second << "}";
}

// === Debug macro ends here ===

main() {
  hs;
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  f(i, 0, n) cin >> v[i].fi >> v[i].se;

  int mi = LONG_LONG_MAX, ma = LONG_LONG_MIN;
  f(i, 0, n) {
    mi = min(mi, v[i].fi + v[i].se);
    ma = max(ma, v[i].fi + v[i].se);
  }
  int ans = ma - mi;
  mi = LONG_LONG_MAX, ma = LONG_LONG_MIN;
  f(i, 0, n) {
    mi = min(mi, v[i].fi - v[i].se);
    ma = max(ma, v[i].fi - v[i].se);
  }
  ans = max(ans, ma - mi);
  cout << ans;
}

Error: WA

Fixed submission:

/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define ve vector
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpl vector<pll>
#define fi first
#define all(a) (a).begin(), (a).end()
#define si(x) (int)((x).size())
#define debug(x)                                                               \\
  cout << #x << " is " << (x) << endl;                                         \\
  cout.flush();
#define se second
#define endl '\\n'
#define f(i, a, b) for (int i = a; i < b; i++)
#define mem(a, x) memset(a, x, sizeof(a))

// const ll mod=998244353;
const ll mod = 1000000000 + 7;
const ll N = 1000000 + 6;
#define M_PI 3.14159265358979323846

// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
// int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
// int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
// int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
// int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x)                                                                 \\
  {                                                                            \\
    ++recur_depth;                                                             \\
    auto x_ = x;                                                               \\
    --recur_depth;                                                             \\
    cerr << string(recur_depth, '\\t') << "\\e[91m" << __func__ << ":"           \\
         << __LINE__ << "\\t" << #x << " = " << x_ << "\\e[39m" << endl;         \\
  }
#else
#define dbg(x)
#endif
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream &>::type
operator<<(Ostream &os, const Cont &v) {
  os << "[";
  for (auto &x : v) {
    os << x << ", ";
  }
  return os << "]";
}
template <typename Ostream, typename... Ts>
Ostream &operator<<(Ostream &os, const pair<Ts...> &p) {
  return os << "{" << p.first << ", " << p.second << "}";
}

// === Debug macro ends here ===

void inp(ll *arr, ll n) {
  for (int i = 0; i < n; i++)
    cin >> arr[i];
}
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
  ll x = a.fi + a.se, y = b.fi + b.se;
  if (x <= y)
    return true;
  else {
    return false;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //  #ifndef ONLINE_JUDGEc
  //   freopen ("INPUT.txt" , "r" , stdin);
  //   freopen ("OUTPUT.txt", "w" , stdout);
  // #endif
  ll n;
  cin >> n;
  vector<pair<ll, ll>> v;
  f(i, 0, n) {
    ll x, y;
    cin >> x >> y;
    v.pb({x, y});
  }
  sort(v.begin(), v.end(), cmp);
  ll ans = abs(v[0].fi - v[n - 1].fi) + abs(v[0].se - v[n - 1].se);
  cout << ans;
}