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

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

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

  vector<long long int> x(N);
  vector<long long int> y(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i);
    // cout << x.at(i) << y.at(i) << endl;
  }

  long long int max_x = x.at(0) - y.at(0);
  long long int min_x = x.at(0) - y.at(0);
  long long int max_y = x.at(0) + y.at(0);
  long long int min_y = x.at(0) + y.at(0);
  long long int max = 0;

  for (int i = 0; i < N; i++) {
    if (max_x < x.at(i) - y.at(i)) {
      max_x = x.at(i) - y.at(i);
    }
    if (min_x > x.at(i) - y.at(i)) {
      min_x = x.at(i) - y.at(i);
    }
    if (max_y < x.at(i) + y.at(i)) {
      max_y = x.at(i) + y.at(i);
    }
    if (min_y > x.at(i) + y.at(i)) {
      min_y = x.at(i) + y.at(i);
    }
  }

  if (llabs(max_x - min_x) < llabs(max_y - min_y)) {
    max = llabs(max_y - min_y);
  } else {
    max = llabs(max_x - min_x);
  }

  cout << max << endl;
}

Error: TLE

Fixed submission:

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

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

  vector<long long int> x(N);
  vector<long long int> y(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i);
    // cout << x.at(i) << y.at(i) << endl;
  }

  long long int max = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (max < llabs(x.at(i) - x.at(j)) + llabs(y.at(i) - y.at(j))) {
        max = llabs(x.at(i) - x.at(j)) + llabs(y.at(i) - y.at(j));
      }
    }
  }

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

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

const long long INF = 1LL << 60;

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

  vector<pair<long long, long long>> p(N);
  long long max_dist = 0;
  set<pair<long long, long long>> candidates;

  // 中心を真ん中にずらす
  for (int i = 0; i < N; ++i) {
    long long x, y;
    cin >> x >> y;
    p[i] = {x, y};

    long long dist = abs(x - 5e8) + abs(y - 5e8);

    if (max_dist < dist) {
      max_dist = dist;
      candidates.clear();
      candidates.insert({x, y});
    } else if (dist == max_dist) {
      candidates.insert({x, y});
    } else {
      continue;
    }
  }

  unordered_map<long long, long long> hightest_y;
  unordered_map<long long, long long> lowest_y;

  for (int i = 0; i < N; ++i) {
    long long x = p[i].first;
    long long y = p[i].second;
    if (hightest_y.count(x) > 0 && y < hightest_y[x])
      continue;
    hightest_y[x] = y;

    if (lowest_y.count(x) > 0 && y > lowest_y[x])
      continue;
    lowest_y[x] = y;
  }

  long long ans = 0;
  for (auto p : candidates) {
    long long cx = p.first;
    long long cy = p.second;
    for (auto hmp : hightest_y) {
      long long x = hmp.first;
      long long y = hmp.second;
      ans = max(ans, abs(cx - x) + abs(cy - y));
    }

    for (auto lmp : lowest_y) {
      long long x = lmp.first;
      long long y = lmp.second;
      ans = max(ans, abs(cx - x) + abs(cy - y));
    }
  }

  cout << ans << endl;
}

Error: WA

Fixed submission:

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

const long long INF = 1LL << 60;

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

  vector<pair<long long, long long>> p(N);
  long long min_dist = INF;

  set<pair<long long, long long>> candidates;

  for (int i = 0; i < N; ++i) {
    long long x, y;
    cin >> x >> y;
    p[i] = {x, y};

    if ((x + y) < min_dist) {
      min_dist = x + y;
      candidates.clear();
      candidates.insert({x, y});
    } else if ((x + y) == min_dist) {
      candidates.insert({x, y});
    } else {
      continue;
    }
  }

  // highest y
  vector<long long> hightest_y(200010, -1);
  vector<long long> lowest_y(200010, -1);

  for (int i = 0; i < N; ++i) {
    long long x = p[i].first;
    long long y = p[i].second;
    if (hightest_y[x] != -1 && y < hightest_y[x])
      continue;
    hightest_y[x] = y;

    if (lowest_y[x] != -1 && y > lowest_y[x])
      continue;
    lowest_y[x] = y;
  }

  // long long ans = 0;
  // for(auto p : candidates){
  //     long long cx = p.first;
  //     long long cy = p.second;
  //     for(int col=0; col<200010; ++col){
  //         if(hightest_y[col] == -1) continue;
  //         ans = max( ans, abs(cx - col) + abs(cy - hightest_y[col]) );
  //         ans = max( ans, abs(cx - col) + abs(cy - lowest_y[col]) );
  //     }
  // }

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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INCANT                                                                 \\
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0),                            \\
      cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7LL;
const int INF = 2e9;
int N;
int A[200005], B[200005];

int main() {
  INCANT;
  cin >> N;
  int a, b;
  rep(i, N) {
    cin >> a >> b;
    A[i] = a + b;
    B[i] = a - b;
  }
  sort(A, A + N);
  sort(B, B + N);

  cout << max(A[N - 1] - A[0], B[N - 1] - B[0]) << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INCANT                                                                 \\
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0),                            \\
      cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7LL;
const int INF = 2e9;
int N;
typedef pair<int, int> P;
P A[200005];
vector<P> C, D;

int dist(P p1, P p2) {
  return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main() {
  INCANT;
  cin >> N;
  int a, b;
  rep(i, N) {
    cin >> a >> b;
    A[i] = P(a, b);
  }
  sort(A, A + N);
  int base = dist(A[0], A[N - 1]); // 基準
  if (N == 2) {
    cout << base << endl;
    return 0;
  }
  C.push_back(P(A[0].second, A[0].first));
  C.push_back(P(A[N - 1].second, A[N - 1].first));
  for (int d = 1; d < N - 1; d++) {
    int now = max(dist(A[d], A[0]), dist(A[d], A[N - 1]));
    if (base < now) {
      base = now;
      C.push_back(P(A[d].second, A[d].first));
    }
  }
  sort(ALL(C));
  if (dist(C[0], C[N - 1]) > base) {
    D.push_back(C[0]);
    D.push_back(C[N - 1]);
    base = dist(C[0], C[N - 1]);
  } else
    D.push_back(C[0]);
  for (int d = 2; d < C.size(); d++) {
    int now = max(dist(C[d], C[0]), dist(C[d], C[C.size() - 1]));
    if (base < now) {
      base = now;
      D.push_back(C[d]);
    }
  }
  rep(i, D.size() - 1) {
    for (int j = i + 1; j < D.size(); j++) {
      if (dist(D[i], D[j]) > base)
        base = dist(D[i], D[j]);
    }
  }
  cout << base << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long n, x, y, arr[200005], brr[200005], ans;

int main() {
  cin >> n;

  for (long long i = 1; i <= n; i++) {
    cin >> x >> y;

    arr[i] = x + y;
    brr[i] = x - y;
  }
  sort(arr + 1, arr + n + 1);
  sort(brr + 1, brr + n + 1);

  ans = max(abs(arr[n] - arr[1]), abs(brr[n] - brr[1]));
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int n, x[200005], y[200005], ans;

int main() {
  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<ll> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];

  vector<ll> a(n), b(n);

  ll a_max = -1e11, b_max = -1e11, a_min = 1e11, b_min = 1e11;

  rep(i, n) {
    a[i] = x[i] + y[i];
    b[i] = x[i] - y[i];
    a_max = max(a_max, a[i]);
    b_max = max(b_max, b[i]);
    a_min = min(a_min, a[i]);
    b_min = min(b_min, b[i]);
  }
  ll ans = max(a_max - a_min, b_max - b_min);
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<ll> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];

  ll ans = 0;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N;
  cin >> N;
  set<ll> Z, W;
  for (int i = 0; i < N; i++) {
    ll x, y;
    cin >> x >> y;
    Z.insert(x - y);
    W.insert(x + y);
  }
  ll z, w;
  z = *Z.rbegin() - *Z.begin();
  w = *W.rbegin() - *W.begin();

  ll mx = (z < w ? w : z);
  cout << mx << endl;
  return (0);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N;
  cin >> N;
  set<pair<ll, ll>> P;
  ll CX = 0;
  ll CY = 0;
  for (int i = 0; i < N; i++) {
    ll X, Y;
    cin >> X >> Y;
    P.insert(pair<ll, ll>(X, Y));
    CX += X;
    CY += Y;
  }
  double cx = (double)CX / (double)P.size();
  double cy = (double)CY / (double)P.size();

  ll mx = 0;

  for (auto it = P.begin(); it != P.end(); it++) {
    for (auto jt = it; jt != P.end(); jt++) {
      ll d = abs(it->first - jt->first) + abs(it->second - jt->second);
      mx = (mx < d ? d : mx);
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<long long int, long long int>
#define vi vector<long long int>
#define vvi vector<vector<long long int>>
#define MP make_pair
#define PB push_back
#define pb pop_back
#define PF push_front
#define pf pop_front
#define MOD 1000000007
#define MT make_tuple

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  ll a[n], b[n], c[n], d[n], maxa = -1e18, maxb = -1e18, maxc = -1e18,
                             maxd = -1e18;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    a[i] = x + y;
    b[i] = x - y;
    c[i] = y - x;
    d[i] = -x - y;
    maxa = max(maxa, a[i]);
    maxb = max(maxb, b[i]);
    maxc = max(maxc, c[i]);
    maxd = max(maxd, d[i]);
  }
  ll ans = -1e18;
  ans = max(ans, maxa + maxd);
  ans = max(ans, maxb + maxc);
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<long long int, long long int>
#define vi vector<long long int>
#define vvi vector<vector<long long int>>
#define MP make_pair
#define PB push_back
#define pb pop_back
#define PF push_front
#define pf pop_front
#define MOD 1000000007
#define MT make_tuple
ll f[5000];
void fac() {
  f[0] = 1;
  for (ll i = 1; i < 5000; i++)
    f[i] = (f[i - 1] * i) % MOD;
}
ll exp(ll x, ll y) {
  ll h = 1;
  x %= MOD;
  while (y) {
    if (y % 2 == 1) {
      h = (h * x) % MOD;
    }
    y /= 2;
    x = (x * x) % MOD;
  }
  return h;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  ll ans = 0;
  fac();
  for (ll i = 1; 3 * i <= n; i++) {
    ll k = n - i * 3;
    ll yo = f[k + i - 1];
    ll p = exp(f[k], MOD - 2);
    ll q = exp(f[i - 1], MOD - 2);
    yo = (yo * p) % MOD;
    yo = (yo * q) % MOD;
    ans = (ans + yo) % MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll xl = -1e9;
const ll yl = -1e9;
const ll xr = 1e9;
const ll yr = -1e9;

int main() {
  ll Max1 = -4e9, Max2 = -4e9;
  ll Min1 = 4e9, Min2 = 4e9;
  int n;
  scanf("%d", &n);
  ll x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &x, &y);
    Max1 = max(abs(x - xl) + abs(y - yl), Max1);
    Min1 = min(abs(x - xl) + abs(y - yl), Min1);
    Max2 = max(abs(x - xr) + abs(y - yr), Max2);
    Min2 = min(abs(x - xr) + abs(y - yr), Min2);
  }
  ll ans = max(Max1 - Min1, Max2 - Min2);
  printf("%lld\\n", ans);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e6 + 10;
struct st {
  int a, b;
} arr[N];
bool cmp(st a, st b) { return a.a + b.a > b.a + b.b; }
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i].a >> arr[i].b;
  }
  sort(arr, arr + n, cmp);
  ll ans = abs(arr[0].a - arr[n - 1].a) + abs(arr[0].b - arr[n - 1].b);
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
const int N = 200005;
const double INF = 1e100;

int a[N][3];
int n;

int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 2; j++)
        scanf("%d", &a[i][j]);
    int ans = 0, mi, mx, t;
    for (int s = 1; s < (1 << 2); s++) {
      mi = INF;
      mx = -INF;
      for (int i = 0; i < n; i++) {
        t = 0;
        for (int j = 0; j < 2; j++) {
          if ((1 << j) & s)
            t += a[i][j];
          else
            t -= a[i][j];
        }
        mi = min(mi, t);
        mx = max(mx, t);
      }
      ans = max(ans, mx - mi);
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
const int N = 100005;
const double INF = 1e100;

int a[N][3];
int n;

int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 2; j++)
        scanf("%d", &a[i][j]);
    int ans = 0, mi, mx, t;
    for (int s = 1; s < (1 << 2); s++) {
      mi = INF;
      mx = -INF;
      for (int i = 0; i < n; i++) {
        t = 0;
        for (int j = 0; j < 2; j++) {
          if ((1 << j) & s)
            t += a[i][j];
          else
            t -= a[i][j];
        }
        mi = min(mi, t);
        mx = max(mx, t);
      }
      ans = max(ans, mx - mi);
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
#define FOR(i, a, b) for (i = a; i <= b; i++)
#define mem(a) memset(a, 0, sizeof a)
#define memn(a) memset(a, -1, sizeof a)
int main() {
  int t = 1;
  // cin>>t;
  while (t--) {
    long long n, mx = INT_MIN, i, j, x, y;
    cin >> n;
    int a[n + 2], b[n + 2];
    for (i = 0; i < n; i++) {
      cin >> x >> y;
      a[i] = (x + y);
      b[i] = (x - y);
    }
    sort(a, a + n);
    sort(b, b + n);
    cout << max((a[n - 1] - a[0]), (b[n - 1] - b[0])) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
#define FOR(i, a, b) for (i = a; i <= b; i++)
#define mem(a) memset(a, 0, sizeof a)
#define memn(a) memset(a, -1, sizeof a)
int main() {
  int t = 1;
  // cin>>t;
  while (t--) {
    long long n, mx = INT_MIN, i, j, x, y;
    cin >> n;
    pair<int, int> p[n + 3];
    for (i = 1; i <= n; i++) {
      cin >> p[i].first >> p[i].second;
    }
    for (i = 1; i <= n - 1; i++) {
      for (j = i + 1; j <= n; j++) {
        x = abs(p[i].first - p[j].first) + abs(p[i].second - p[j].second);
        mx = max(x, mx);
      }
    }
    cout << mx << endl;
  }
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int a[200005], n, b[200005];
const int mod = 1e9 + 7;
int main() {

  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    a[i] = x - y;
    b[i] = x + y;
  }
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n);
  ll ans = max(a[n] - a[1], b[n] - b[1]);
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int a[20005], n, b[20005];
const int mod = 1e9 + 7;
signed main() {

  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    a[i] = x - y;
    b[i] = x + y;
  }
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n);
  ll ans = max(a[n] - a[1], b[n] - b[1]);
  cout << ans;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
#define int long long
int n;
int maxx, maxy, minx, miny;
signed main() {
  scanf("%lld", &n);
  minx = miny = 0xfeeddeadbeef;
  maxx = maxy = -minx;
  for (int i = 1; i <= n; ++i) {
    int x, y;
    scanf("%lld%lld", &x, &y);
    maxx = max(maxx, x + y);
    minx = min(minx, x + y);
    maxy = max(maxy, x - y);
    miny = min(miny, x - y);
  }
  printf("%lld\\n", max(maxx - minx, maxy - miny));
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, x[N], y[N], id[N];
int maxx, maxy, minx, miny;
signed main() {
  scanf("%d", &n);
  minx = miny = 0x7fffffff;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", x + i, y + i);
    maxx = max(maxx, x[i] + y[i]);
    minx = min(minx, x[i] + y[i]);
    maxy = max(maxy, x[i] - y[i]);
    miny = min(miny, x[i] - y[i]);
  }
  printf("%d\\n", max(maxx - minx, maxy - miny));
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  vector<int> sum(n), diff(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    sum[i] = x[i] + y[i];
    diff[i] = x[i] - y[i];
  }
  sort(sum.begin(), sum.end());
  sort(diff.begin(), diff.end());
  cout << max(sum[n - 1] - sum[0], diff[n - 1] - diff[0]) << endl;
}

int main() {

  /*#ifndef ONLINE_JUDGE
          freopen("input.txt","r",stdin);
          freopen("output.txt","w",stdout);
  #endif*/
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // int t;cin >> t;while(t--){solve();}
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<pair<long long, long long>> v;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int dist;
      dist = abs(v[i].f - v[j].f) + abs(v[i].s - v[j].s);
      res = max(res, dist);
    }
  }
  cout << res << "\\n";
}

int main() {

  /*#ifndef ONLINE_JUDGE
          freopen("input.txt","r",stdin);
          freopen("output.txt","w",stdout);
  #endif*/
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // int t;cin >> t;while(t--){solve();}
  solve();
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
// using namespace __gnu_pbds;

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const int64_t INF = 5e18;
const double PI = 2 * acos(0.0);
// template<typename T> using ordered_set = tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int64_t ans = -INF, mn = INF, mx = -INF, mn2 = INF, mx2 = -INF, mn3 = INF,
          mx3 = -INF, mn4 = mn, mx4 = mx;
  for (int i = 0; i < n; i++) {
    int64_t x, y;
    cin >> x >> y;
    mx = max(mx, x + y);
    mn = min(mn, x + y);
    mx2 = max(mx2, x - y);
    mn2 = min(mn2, x - y);
    mx3 = max(mx3, -x + y);
    mn3 = min(mn3, -x + y);
    mx4 = max(mx4, -x - y);
    mn4 = min(mn4, -x - y);
    ans = max(ans, abs(mx - mn));
    ans = max(ans, abs(mx2 - mn2));
    ans = max(ans, abs(mx3 - mn3));
    ans = max(ans, abs(mx4 - mn4));
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

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

using namespace std;
// using namespace __gnu_pbds;

const int N = 2005;
const int MOD = 1e9 + 7;
const int64_t INF = 5e18;
const double PI = 2 * acos(0.0);
// template<typename T> using ordered_set = tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>;

pair<int64_t, int64_t> a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int64_t ans = 0, mn = INF, mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    mx = max(mx, a[i].first + a[i].second);
    mn = min(mn, a[i].first + a[i].second);
  }
  cout << abs(mx - mn) << '\\n';
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

// Solid <candgenesis>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 1;
const ll inf = 1e13 + 7;
typedef pair<ll, ll> LL;

ll n, i, x, y;
ll mx[3], mn[3];
void oper(ll cond, ll val) {
  mn[cond] = min(mn[cond], val);
  mx[cond] = max(mx[cond], val);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
#define task "tst"
  if (fopen(task ".inp", "r")) {
    freopen(task ".inp", "r", stdin);
    freopen(task ".out", "w", stdout);
  }
  cin >> n;
  mn[1] = mn[2] = inf;
  mx[1] = mx[2] = -inf;
  while (n--) {
    cin >> x >> y;
    x += y;
    oper(1, x);
    x -= 2 * y;
    oper(2, x);
  }
  cout << max(mx[1] - mn[1], mx[2] - mn[2]);
}


Error: TLE

Fixed submission:

// Solid <candgenesis>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 1;
const ll inf = 3e9 + 7;
typedef pair<ll, ll> LL;
LL a[N];
ll n, i;
map<ll, ll> bit[2];
void upd(ll p, ll val, ll cond) {
  for (ll i = p; i < inf; i += i & -i) {
    if (!bit[cond].count(i))
      bit[cond][i] = val;
    else
      bit[cond][i] = min(bit[cond][i], val);
  }
}
ll Get(ll p, ll cond) {
  ll res = inf;
  for (ll i = p; i > 0; i -= i & -i)
    if (bit[cond].count(i))
      res = min(res, bit[cond][i]);
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
#define task "test"
  if (fopen(task ".inp", "r")) {
    freopen(task ".inp", "r", stdin);
    freopen(task ".out", "w", stdout);
  }
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i].fs >> a[i].sc;
  sort(a + 1, a + n + 1);
  ll ans = 0;
  for (i = 1; i <= n; i++) {
    ll p = Get(inf - a[i].sc, 1), q = Get(a[i].sc, 0); // cout<<p<<" "<<q<<"\\n";
    ans = max(ans, max(a[i].fs + a[i].sc - q, a[i].fs - a[i].sc - p));
    upd(a[i].sc, a[i].fs + a[i].sc, 0);
    upd(inf - a[i].sc, a[i].fs - a[i].sc, 1);
  }
  cout << ans;
}