alexjercan/bugnet huggingface dataset:
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mxN = 1e5;
const ll mod = 1e9 + 7;

ll pow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b % 2 != 0)
      r = (r * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return r;
}

const int sz = 5e5 + 20;
ll fact[sz], inv[sz];
void pre() {
  fact[0] = 1;
  inv[0] = pow(fact[0], mod - 2);
  for (int i = 1; i < sz; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
}

int spf[10];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < mxN; i++)
    spf[i] = i;
  for (int i = 4; i < mxN; i += 2)
    spf[i] = 2;
  for (int i = 3; i * i < mxN; i++) {
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  ll ans = 0;

  vector<vector<ll>> v(n, vector<ll>(2));
  for (int i = 0; i < n; i++)
    cin >> v[i][0] >> v[i][1];

  vector<int> s1(n);
  vector<int> s2(n);

  for (int i = 0; i < n; i++) {
    int x = v[i][0];
    int y = v[i][1];
    s1[i] = x + y;
    s2[i] = x - y;
  }

  sort(s1.begin(), s1.end());
  sort(s2.begin(), s2.end());

  cout << max((s1[n - 1] - s1[0]), (s2[n - 1] - s2[0])) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mxN = 1e5;
const ll mod = 1e9 + 7;

ll pow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b % 2 != 0)
      r = (r * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return r;
}

const int sz = 5e5 + 20;
ll fact[sz], inv[sz];
void pre() {
  fact[0] = 1;
  inv[0] = pow(fact[0], mod - 2);
  for (int i = 1; i < sz; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
}

int spf[10];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < mxN; i++)
    spf[i] = i;
  for (int i = 4; i < mxN; i += 2)
    spf[i] = 2;
  for (int i = 3; i * i < mxN; i++) {
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  ll ans = 0;

  vector<vector<ll>> v(n, vector<ll>(2));
  for (int i = 0; i < n; i++)
    cin >> v[i][0] >> v[i][1];

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = max(ans, abs(v[i][0] - v[j][0]) + abs(v[i][1] - v[j][1]));
    }
  }

  cout << ans << endl;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
int main(void) {
  // Your code here!
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, ans, ans1, ans2, n;
  ans1 = INT_MAX;
  ans2 = INT_MIN;
  ans = 0;
  cin >> n;
  int x[n], y[n];
  for (i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    ans1 = min(ans1, x[i] + y[i]);
    ans2 = max(ans2, x[i] + y[i]);
  }
  ans = max(ans, abs(ans2 - ans1));
  ans1 = INT_MAX;
  ans2 = INT_MIN;
  for (i = 0; i < n; i++) {
    ans1 = min(ans1, x[i] - y[i]);
    ans2 = max(ans2, x[i] - y[i]);
  }
  ans = max(ans, abs(ans2 - ans1));
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
int main(void) {
  // Your code here!
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int ans, n, x, y;
  ans = 0;
  cin >> n;
  map<int, set<int>> m;
  while (n--) {
    cin >> x >> y;
    m[x].insert(y);
  }
  for (auto it : m) {
    for (auto itr : m)
      ans =
          max(ans, abs(it.ff - itr.ff) +
                       max(abs((*m[it.ff].begin()) - (*(--m[itr.ff].end()))),
                           abs((*m[itr.ff].begin()) - (*(--m[it.ff].end())))));
  }
  cout << ans;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

typedef long long int ll;
ll pts[400005][2] = {0};

ll mnht(ll pt[400005][2], int kth, int idx, int d) {
  ll dist = 0;

  for (int i = 0; i < d; i++) {
    dist += abs(pt[kth][i] - pt[idx][i]);
  }

  return dist;
}
ll max_cmb(ll cmbn[2], ll pt[400005][2], int n, int d) {
  ll pk = 0;
  ll idx = 0;

  for (int i = 0; i < n; i++) {
    ll val = 0;

    for (int j = 0; j < d; j++) {
      val += (1 - 2 * cmbn[j]) * pt[i][j];
    }

    if (val > pk) {
      pk = val;
      idx = i;
    }
  }

  return idx;
}

int main() {
  int n, d;
  cin >> n;
  d = 2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++)
      cin >> pts[i][j];
  }

  ll pk[2 << d];

  for (int j = 0; j < 1 << (d); j++) {
    ll cmbn[2] = {0};
    for (int dig = 0; dig < d; dig++) {
      if (j & 1 << dig)
        cmbn[dig] = 1;
    }

    pk[j] = max_cmb(cmbn, pts, n, d);
  }

  ll maxd = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 1 << (d); j++)
      maxd = max(maxd, mnht(pts, i, pk[j], d));
  }

  cout << maxd << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

typedef long long int ll;
ll pts[100005][2] = {0};

ll mnht(ll pt[100005][2], int kth, int idx, int d) {
  ll dist = 0;

  for (int i = 0; i < d; i++) {
    dist += abs(pt[kth][i] - pt[idx][i]);
  }

  return dist;
}
ll max_cmb(ll cmbn[2], ll pt[100005][2], int n, int d) {
  ll pk = 0;
  ll idx = 0;

  for (int i = 0; i < n; i++) {
    ll val = 0;

    for (int j = 0; j < d; j++) {
      val += (1 - 2 * cmbn[j]) * pt[i][j];
    }

    if (val > pk) {
      pk = val;
      idx = i;
    }
  }

  return idx;
}

int main() {
  int n, d;
  cin >> n;
  d = 2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++)
      cin >> pts[i][j];
  }

  ll pk[2 << d];

  for (int j = 0; j < 1 << (d); j++) {
    ll cmbn[2] = {0};
    for (int dig = 0; dig < d; dig++) {
      if (j & 1 << dig)
        cmbn[dig] = 1;
    }

    pk[j] = max_cmb(cmbn, pts, n, d);
  }

  ll maxd = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 1 << (d); j++)
      maxd = max(maxd, mnht(pts, i, pk[j], d));
  }

  cout << maxd << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define sync                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define input(arr, n)                                                          \\
  for (ll i1 = 0; i1 < n; i1++)                                                \\
  cin >> arr[i1]
#define mod 1000000007
#define F first
#define S second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<ll, null_type, less_equal<ll>, rb_tree_tag,                             \\
       tree_order_statistics_node_update> // s.order_of_key(val)
                                          // *s.find_by_order(ind)
using namespace std;

const int N = 1e6 + 5;
int main() {
  sync;
  ll n;
  cin >> n;
  vector<pair<ll, ll>> v(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i].F >> v[i].S;
  ll ans = 0, minm = 1e18, maxm = -1e18;
  for (ll i = 0; i < n; i++) {
    minm = min(minm, v[i].F + v[i].S);
    maxm = max(maxm, v[i].F + v[i].S);
  }
  ans = maxm - minm;
  minm = 1e18, maxm = -1e18;
  for (ll i = 0; i < n; i++) {
    minm = min(minm, v[i].F - v[i].S);
    maxm = max(maxm, v[i].F - v[i].S);
  }
  ans = max(ans, maxm - minm);
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define sync                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define input(arr, n)                                                          \\
  for (ll i1 = 0; i1 < n; i1++)                                                \\
  cin >> arr[i1]
#define mod 1000000007
#define F first
#define S second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<ll, null_type, less_equal<ll>, rb_tree_tag,                             \\
       tree_order_statistics_node_update> // s.order_of_key(val)
                                          // *s.find_by_order(ind)
using namespace std;

const int N = 1e6 + 5;
int main() {
  sync;
  ll n;
  cin >> n;
  vector<pair<ll, ll>> v(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i].F >> v[i].S;
  ll ans = 0;
  for (ll i = 0; i < n; i++)
    for (ll j = 0; j < n; j++)
      ans = max(ans, abs(v[i].F - v[j].F) + abs(v[i].S - v[j].S));
  cout << ans;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

/*
ll binpow(ll a, ll b) {
    ll res=1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  vector<pair<ll, ll>> v;
  ll ans;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }
  // sort(v.begin(),v.end());
  vector<ll> a, b;
  for (ll i = n - 1; i >= 0; i--) {
    a.push_back((v[i].first + v[i].second));
    b.push_back((v[i].first - v[i].second));
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ans = a[n - 1] - a[0];
  ans = max(ans, (b[n - 1] - b[0]));

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

/*
ll binpow(ll a, ll b) {
    ll res=1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  vector<pair<ll, ll>> v;
  ll ans;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    v.push_back({x, y});
    // sort(v.begin(),v.end());
    vector<ll> a, b;
    for (ll i = n - 1; i >= 0; i--) {
      a.push_back((v[i].first + v[i].second));
      b.push_back((v[i].first - v[i].second));
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ans = a[n - 1] - a[0];
    ans = max(ans, (b[n - 1] - b[0]));
  }
  cout << ans << endl;

  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> z(n), w(n);
  for (int i = 0; i < n; ++i) {
    long long x, y;
    cin >> x >> y;
    z[i] = x + y;
    w[i] = x - y;
  }
  sort(z.begin(), z.end());
  sort(w.begin(), w.end());
  long long res = max(z[n - 1] - z[0], w[n - 1] - w[0]);

  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int n;
vector<int> x, y;
int main() {
  cin >> n;
  x.resize(n);
  y.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }

  long long res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      res = max<long long>(res, abs(x[i] - x[j]) + abs(y[i] - y[j]));
    }
  }

  cout << res << endl;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define db double
#define pb push_back
#define wrln cout << '\\n';
#define pii pair<int, int>
using namespace std;

const int H = 1e9 + 7;
const int N = 2e5 + 100;

ll x[N], y[N], n, res, d[6];
ll xz[6], yz[6];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  /*   freopen("test12.inp","r",stdin);
     freopen("test.out","w",stdout);*/

  d[1] = d[2] = d[3] = d[4] = LLONG_MIN;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
    if (d[1] < x[i] + y[i]) {
      d[1] = x[i] + y[i];
      xz[1] = x[i];
      yz[1] = y[i];
    }
    if (d[2] < x[i] - y[i]) {
      d[2] = x[i] - y[i];
      xz[2] = x[i];
      yz[2] = y[i];
    }
    if (d[3] < -x[i] + y[i]) {
      d[3] = -x[i] + y[i];
      xz[3] = x[i];
      yz[3] = y[i];
    }
    if (d[4] < -x[i] - y[i]) {
      d[4] = -x[i] - y[i];
      xz[4] = x[i];
      yz[4] = y[i];
    }
  }
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      res = max(res, abs(x[j] - xz[i]) + abs(y[j] - yz[i]));
    }
  }
  cout << res;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define db double
#define pb push_back
#define wrln cout << '\\n';
#define pii pair<int, int>
using namespace std;
const int H = 1e9 + 7;
const int N = 2e5 + 100;

ll x[N], y[N], n, res;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      res = max(res, abs(x[i] - x[j]) + abs(y[i] - y[j]));
    }
  }
  cout << res;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N;
  cin >> N;

  using coord = pair<int64_t, int64_t>;
  vector<coord> data(N);
  int64_t bufx, bufy;
  for (int64_t i = 0; i < N; i++) {
    cin >> bufx >> bufy;
    data.at(i) = make_pair(bufx, bufy);
  }

  int64_t inc = 2'000'000'000;
  int64_t exc = -1;
  while (abs(inc - exc) > 1) {
    int64_t mid = (inc + exc) / 2;

    auto is_inc = [&](int64_t mid) {
      int64_t plus_upper = INT_MAX;
      int64_t minus_upper = INT_MAX;
      int64_t plus_lower = INT_MIN;
      int64_t minus_lower = INT_MIN;
      for (auto [x, y] : data) {
        plus_upper = min(plus_upper, x + y + mid);
        minus_upper = min(minus_upper, x - y + mid);
        plus_lower = max(plus_lower, x + y - mid);
        minus_lower = max(minus_lower, x - y - mid);
      }

      bool bool_mid = true;
      for (auto [x, y] : data) {
        int64_t plus = x + y;
        int64_t minus = x - y;
        if (plus_lower <= plus and plus <= plus_upper and
            minus_lower <= minus and minus <= minus_upper) {
          continue;
        } else {
          bool_mid = false;
          break;
        }
      }

      return bool_mid;
    };

    if (is_inc(mid)) {
      inc = mid;
    } else {
      exc = mid;
    }
  }

  int64_t ans = inc;

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;

  using coord = pair<int, int>;
  vector<coord> data(N);
  int bufx, bufy;
  for (int i = 0; i < N; i++) {
    cin >> bufx >> bufy;
    data.at(i) = make_pair(bufx, bufy);
  }

  int inc = 2'000'000'000;
  int exc = -1;
  while (abs(inc - exc) > 1) {
    int mid = (inc + exc) / 2;

    auto is_inc = [&](int mid) {
      int plus_upper = INT_MAX;
      int minus_upper = INT_MAX;
      int plus_lower = INT_MIN;
      int minus_lower = INT_MIN;
      for (auto [x, y] : data) {
        plus_upper = min(plus_upper, x + y + mid);
        minus_upper = min(minus_upper, x - y + mid);
        plus_lower = max(plus_lower, x + y - mid);
        minus_lower = max(minus_lower, x - y - mid);
      }

      bool bool_mid = true;
      for (auto [x, y] : data) {
        int plus = x + y;
        int minus = x - y;
        if (plus_lower <= plus and plus <= plus_upper and
            minus_lower <= minus and minus <= minus_upper) {
          continue;
        } else {
          bool_mid = false;
          break;
        }
      }

      return bool_mid;
    };

    if (is_inc(mid)) {
      inc = mid;
    } else {
      exc = mid;
    }
  }

  int ans = inc;

  cout << ans << endl;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

struct pr {
  int x, y;
};

typedef struct pr pp;

bool compareble(pp a, pp b) { return (a.x + a.y) < (b.y + b.x); }

bool compareblee(pp a, pp b) { return abs(a.x - a.y) < abs(b.x - b.y); }

int main() {

  int n, maxy = 1, index;

  ll maxdist = 0, u, v;

  cin >> n;

  pp ar[n];

  for (int i = 0; i < n; i++)
    cin >> ar[i].x >> ar[i].y;

  sort(ar, ar + n, compareble);

  for (int i = 0; i < n; i++) {
    if (ar[i].y > maxy) {
      maxy = ar[i].y;
      index = i;
    }
  }

  for (int i = 0; i < n; i++) {
    u = abs(ar[i].y - ar[0].y);

    u += abs(ar[i].x - ar[0].x);

    v = abs(ar[i].y - ar[n - 1].y);

    v += abs(ar[i].x - ar[n - 1].x);

    maxdist = max(max(u, v), maxdist);
  }

  sort(ar, ar + n, compareblee);

  for (int i = 0; i < n; i++) {
    u = abs(ar[i].y - ar[0].y);

    u += abs(ar[i].x - ar[0].x);

    v = abs(ar[i].y - ar[n - 1].y);

    v += abs(ar[i].x - ar[n - 1].x);

    maxdist = max(max(u, v), maxdist);
  }

  sort(ar, ar + n, compareblee);

  cout << maxdist;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

struct pr {
  int x, y;
};

typedef struct pr pp;

bool compareble(pp a, pp b) {

  if ((a.x + a.y) != (b.x + b.y))
    return (a.x + a.y) < (b.y + b.x);

  else
    return true;
}
int main() {

  int n, maxy = 1, index;

  ll maxdist = 0, u, v;

  cin >> n;

  pp ar[n];

  for (int i = 0; i < n; i++)
    cin >> ar[i].x >> ar[i].y;

  sort(ar, ar + n, compareble);

  for (int i = 0; i < n; i++) {
    if (ar[i].y > maxy) {
      maxy = ar[i].y;
      index = i;
    }
  }

  for (int i = 0; i < n; i++) {
    u = (ll)abs(ar[i].x - ar[0].x) + (ll)abs(ar[i].y - ar[0].y);

    v = (ll)abs(ar[i].x - ar[n - 1].x) + (ll)abs(ar[i].y - ar[n - 1].y);

    maxdist = max(max(u, v), maxdist);
  }

  cout << maxdist;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

typedef pair<int, int> P;

int N;
int x[200005], y[200005];
P p[200005], q[200005];

int d(int i, int j) {
  // printf("i = %d, j = %d\\n", i, j);
  return abs(x[i] - x[j]) + abs(y[i] - y[j]);
}

void solve() {
  int mx = -1;
  for (int i = 0; i < N; i++) {
    if (mx < x[i])
      mx = x[i];
  }

  for (int i = 0; i < N; i++) {
    p[i] = make_pair(x[i] + y[i], i);
    q[i] = make_pair((mx - x[i]) + y[i], i);
  }

  sort(p, p + N);
  sort(q, q + N);

  int ans = -1;
  for (int i = 0; i <= N / 20; i++) {
    for (int j = 0; j <= N / 20; j++) {
      // printf("check for p[%d] and p[%d]: ", i, N-1-j);
      int t = d(p[i].second, p[N - 1 - j].second);
      if (ans < t)
        ans = t;

      int s = d(q[i].second, q[N - 1 - j].second);
      if (ans < s)
        ans = s;
    }
  }
  printf("%d\\n", ans);
}

void solve2() {
  int ans = -1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int t = d(i, j);
      if (ans < t)
        ans = t;
    }
  }
  printf("%d\\n", ans);
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", x + i, y + i);
  }
  // solve2();
  solve();
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
using namespace std;

typedef pair<int, pair<int, pair<int, int>>> P;

int N;
int x[200005], y[200005];
P p[200005];

int d(int i, int j) {
  // printf("i = %d, j = %d\\n", i, j);
  return abs(x[i] - x[j]) + abs(y[i] - y[j]);
}

void solve() {
  for (int i = 0; i < N; i++) {
    p[i] = make_pair(x[i] + y[i], make_pair(i, make_pair(x[i], y[i])));
  }

  sort(p, p + N);
  for (int i = 0; i < N; i++) {
    // printf("p[%d] = (%d, %d, %d, %d)\\n", i, p[i].first, p[i].second.first,
    // p[i].second.second.first, p[i].second.second.second);
  }

  int ans = -1;
  for (int i = 0; i <= N / 10; i++) {
    for (int j = 0; j <= N / 10; j++) {
      // printf("check for p[%d] and p[%d]: ", i, N-1-j);
      int t = d(p[i].second.first, p[N - 1 - j].second.first);
      if (ans < t)
        ans = t;
    }
  }
  for (int i = -N / 10; i <= N / 10; i++) {
    for (int j = -N / 10; j <= N / 10; j++) {
      // printf("check for p[%d] and p[%d]: ", N/2+i, N/2+j);
      int t = d(p[N / 2 + i].second.first, p[N / 2 + j].second.first);
      if (ans < t)
        ans = t;
    }
  }
  printf("%d\\n", ans);
}

void solve2() {
  int ans = -1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int t = d(i, j);
      if (ans < t)
        ans = t;
    }
  }
  printf("%d\\n", ans);
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", x + i, y + i);
  }
  // solve2();
  solve();
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define rep1(i, a, b) for (int i = a; i < b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define mod 1000000009
#define garou                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
using namespace std;
int pow(int p, int r, int m) {
  int ans = 1;
  while (r > 0) {
    if (r & 1) {
      ans = ((ans % m) * (p % m)) % m;
    }
    r = r >> 1;
    p = ((p % m) * (p % m)) % m;
  }
  return ans;
}
signed main() {
  garou;
  int n;
  cin >> n;
  int min1 = INT_MAX, min2 = INT_MAX, max1 = INT_MIN, max2 = INT_MIN;
  rep1(i, 0, n) {
    int a, b;
    cin >> a >> b;
    min1 = min(min1, a + b);
    min2 = min(min2, a - b);
    max1 = max(max1, a + b);
    max2 = max(max2, a - b);
  }
  cout << max(max2 - min2, max1 - min1);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define rep1(i, a, b) for (int i = a; i < b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define mod 1000000009
#define garou                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
using namespace std;
int pow(int p, int r, int m) {
  int ans = 1;
  while (r > 0) {
    if (r & 1) {
      ans = ((ans % m) * (p % m)) % m;
    }
    r = r >> 1;
    p = ((p % m) * (p % m)) % m;
  }
  return ans;
}
signed main() {
  garou;
  int n;
  cin >> n;
  vector<vector<int>> v(n, vector<int>(n, 0));
  int min1 = INT_MAX, min2 = INT_MAX, max1 = INT_MIN, max2 = INT_MIN;
  rep1(i, 0, n) {
    cin >> v[i][0] >> v[i][1];
    min1 = min(min1, v[i][0] + v[i][1]);
    min2 = min(min2, v[i][0] - v[i][1]);
    max1 = max(max1, v[i][0] + v[i][1]);
    max2 = max(max2, v[i][0] - v[i][1]);
  }
  cout << max(max2 - min2, max1 - min1);
}