Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;

#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) (lower_bound(all(x), y) - x.begin())
#define ubd(x, y) (upper_bound(all(x), y) - x.begin())
mt19937
    rng(chrono::steady_clock::now()
            .time_since_epoch()
            .count()); // can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) {
  return rng() % (y + 1 - x) + x;
} // inclusivesss
string inline to_string(char c) {
  string s(1, c);
  return s;
}
template <typename T> inline T gcd(T a, T b) {
  return a == 0 ? llabs(b) : gcd(b % a, a);
}

using ll = long long;
using ld = long double;
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
using pi = pair<ll, ll>;
using spi = pair<ll, pi>;
using dpi = pair<pi, pi>;

#define LLINF ((long long)1e18)
#define INF int(1e9 + 1e6)
#define MAXN (200006)
ll n, ans, tmp;
pi A[MAXN];
multiset<pi> h, l;
ll dist(ll x, ll y) { return abs(A[x].f - A[y].f) + abs(A[x].s - A[y].s); }
int main() {
  FAST cin >> n;
  FOR(i, 1, n) cin >> A[i].f >> A[i].s;
  tmp = -LLINF;
  FOR(i, 1, n) tmp = max(tmp, A[i].s);
  ans = tmp, tmp = LLINF;
  FOR(i, 1, n) tmp = min(tmp, A[i].s);
  ans -= tmp;
  sort(A + 1, A + n + 1);
  FOR(i, 1, n) {
    auto tmp = h.lower_bound(pi(A[i].s, 0));
    if (tmp != h.end())
      ans = max(ans, dist(tmp->s, i));
    tmp = l.upper_bound(pi(A[i].s, LLINF));
    if (tmp != l.begin())
      --tmp, ans = max(ans, dist(tmp->s, i));
    if (h.empty() || (--h.end())->f < A[i].s) {
      while (h.size()) {
        auto tmp = (--h.end())->s;
        if (A[i].s - A[tmp].s < A[i].f - A[tmp].f)
          break;
        h.erase(--h.end());
      }
      h.ins(pi(A[i].s, i));
    }
    if (l.empty() || l.begin()->f > A[i].s) {
      while (l.size()) {
        auto tmp = l.begin()->f;
        if (A[tmp].s - A[i].s < A[i].f - A[tmp].f)
          break;
        l.erase(l.begin());
      }
      l.ins(pi(A[i].s, i));
    }
  }
  cout << ans << '\n';
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;

#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) (lower_bound(all(x), y) - x.begin())
#define ubd(x, y) (upper_bound(all(x), y) - x.begin())
mt19937
    rng(chrono::steady_clock::now()
            .time_since_epoch()
            .count()); // can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) {
  return rng() % (y + 1 - x) + x;
} // inclusivesss
string inline to_string(char c) {
  string s(1, c);
  return s;
}
template <typename T> inline T gcd(T a, T b) {
  return a == 0 ? llabs(b) : gcd(b % a, a);
}

using ll = long long;
using ld = long double;
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
using pi = pair<ll, ll>;
using spi = pair<ll, pi>;
using dpi = pair<pi, pi>;

#define LLINF ((long long)1e18)
#define INF int(1e9 + 1e6)
#define MAXN (200006)
ll n, ans, tmp;
pi A[MAXN];
multiset<pi> h, l;
ll dist(ll x, ll y) { return abs(A[x].f - A[y].f) + abs(A[x].s - A[y].s); }
int main() {
  FAST cin >> n;
  FOR(i, 1, n) cin >> A[i].f >> A[i].s;
  tmp = -LLINF;
  FOR(i, 1, n) tmp = max(tmp, A[i].s);
  ans = tmp, tmp = LLINF;
  FOR(i, 1, n) tmp = min(tmp, A[i].s);
  ans -= tmp;
  sort(A + 1, A + n + 1);
  FOR(i, 1, n) {
    auto tmp = h.lower_bound(pi(A[i].s, 0));
    if (tmp != h.end())
      ans = max(ans, dist(tmp->s, i));
    tmp = l.upper_bound(pi(A[i].s, LLINF));
    if (tmp != l.begin())
      --tmp, ans = max(ans, dist(tmp->s, i));
    if (h.empty() || (--h.end())->f < A[i].s) {
      while (h.size()) {
        auto tmp = (--h.end())->s;
        if (A[i].s - A[tmp].s < A[i].f - A[tmp].f)
          break;
        h.erase(--h.end());
      }
      h.ins(pi(A[i].s, i));
    }
    if (l.empty() || l.begin()->f > A[i].s) {
      while (l.size()) {
        auto tmp = l.begin()->s;
        if (A[tmp].s - A[i].s < A[i].f - A[tmp].f)
          break;
        l.erase(l.begin());
      }
      l.ins(pi(A[i].s, i));
    }
  }
  cout << ans << '\n';
}