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

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
ll N;

struct Axis {
  ll x, y;
  Axis(ll in_x, ll in_y) {
    x = in_x;
    y = in_y;
  }
};

vector<Axis> A;

ll mandist(Axis a, Axis b) { return abs(a.x - b.x) + abs(a.y - b.y); }

ll solver() {
  ll mx = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ll md = mandist(A[i], A[j]);
      if (mx < md) {
        mx = md;
      }
    }
  }
  return mx;
}

ll solver2() {

  // xi - yi
  ll max0 = LLONG_MIN, min0 = LLONG_MAX;
  ll max1 = LLONG_MIN, min1 = LLONG_MAX;
  for (int i = 0; i < N; i++) {
    {
      ll num0 = A[i].x - A[i].y;
      if (max0 < num0) {
        max0 = num0;
      }
      if (min0 > num0) {
        min0 = num0;
      }
    }

    {
      ll num1 = A[i].x + A[i].y;
      if (max1 < num1) {
        max1 = num1;
      }
      if (min1 > num1) {
        min1 = num1;
      }
    }
  }

  ll can0 = max0 - min0;
  ll can1 = max1 - min1;
  if (can0 > can1)
    return can0;
  return can1;
}

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

  for (int i = 0; i < N; i++) {
    ll x, y;
    cin >> x >> y;
    A.push_back(Axis(x, y));
    cin.ignore();
  }
  cout << solver2() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
ll N;

struct Axis {
  ll x, y;
  Axis(ll in_x, ll in_y) {
    x = in_x;
    y = in_y;
  }
};

vector<Axis> A;

ll mandist(Axis a, Axis b) { return abs(a.x - b.x) + abs(a.y - b.y); }

ll solver() {
  ll mx = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ll md = mandist(A[i], A[j]);
      if (mx < md) {
        mx = md;
      }
    }
  }
  return mx;
}

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

  for (int i = 0; i < N; i++) {
    ll x, y;
    cin >> x >> y;
    A.push_back(Axis(x, y));
    cin.ignore();
  }
  cout << solver() << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> v[n + 10];
  ll i, j, k;
  ll a, b;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    j = a + b;
    v[0].push_back(j);
    j = a - b;
    v[1].push_back(j);
    j = -a + b;
    v[2].push_back(j);
  }
  for (i = 0; i < 3; i++) {
    sort(v[i].begin(), v[i].end());
  }
  ll res = 0;
  for (i = 0; i < 3; i++) {
    n = v[i].size();
    res = max(res, (v[i][n - 1] - v[i][0]));
  }
  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<pair<ll, ll>> vp;
  ll i, j, k;
  ll a, b;
  map<pair<ll, ll>, ll> mp;
  pair<ll, ll> p;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    p = {a, b};
    if (mp[p])
      continue;
    mp[p] = 1;
    vp.push_back({a, b});
  }
  n = vp.size();
  ll mx = 0;
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      ll d = abs(vp[i].first - vp[j].first) + abs(vp[i].second - vp[j].second);
      mx = max(mx, d);
    }
  }
  cout << mx << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

/*
题意：给定N个D维坐标。求最远曼哈顿距离。
解法：对于两个二维坐标A(xi,yi),B(xj,yj).其曼哈顿距离可能为以下四种情况：
(xi-xj)+(yi-yj), (xj-xi)+(yi-yj), (xi-xj)+(yj-yi), (xj-xi)+(yj-yi)
将坐标参数按点来分配之后变形如下：
(xi+yi)-(xj+yj), (-xi+yi)-(-xj+yj), (xi-yi)-(xj-yj), (-xi-yi)-(-xj-yj)
易得每项两个点的参数前的正负符号是一样的。这规律在D维下易证通用。
我们且称如上的（xi+yi）等为点A的“11”状态下的本点有效距离。
由此， 每个坐标参数的正负状态下的最长有效距离减去最短有效距离 即是当前
正负状态下的最远曼哈顿距离。再枚举每个状态，取每个状态的最远曼哈顿距离
的最大值即为答案。
*/

#include <bits/stdc++.h>
using namespace std;
#define INF 9999999999999
#define D 2      // 空间维数
#define M 200005 // 坐标个数
#define int long long
struct Point {
  int x[D];
} pt[M];
int dis[1 << D][M], minx[1 << D], maxx[1 << D];

// 去掉绝对值后有2^D种可能
void Get(int N) // 取得所有点在指定状态（S）下的“本点有效距离”
{
  int tot = (1 << D);
  for (int s = 0; s < tot; s++) // 遍历所有维数正负状态
  {
    int coe[D];
    for (int i = 0; i < D; i++) // 设定当前状态的具体正负参数
      if (s & (1 << i))
        coe[i] = -1;
      else
        coe[i] = 1;

    for (int i = 0; i < N;
         i++) // 遍历所有点，确定每个点在当前状态下的“本点有效距离”
    {
      dis[s][i] = 0;
      for (int j = 0; j < D; j++)
        dis[s][i] = dis[s][i] + coe[j] * pt[i].x[j];
    }
  }
}
// 取每种可能中的最大差距
void Solve(int N) {
  int tot = (1 << D);
  int tmp, ans;
  for (int s = 0; s < tot; s++) {
    minx[s] = INF;
    maxx[s] = -INF;
    for (int i = 0; i < N; i++) {
      if (minx[s] > dis[s][i])
        minx[s] = dis[s][i];
      if (maxx[s] < dis[s][i])
        maxx[s] = dis[s][i];
    }
  }
  ans = 0;
  for (int s = 0; s < tot; s++) {
    tmp = maxx[s] - minx[s];
    if (tmp > ans)
      ans = tmp;
  }

  cout << ans << "\\n";
}

signed main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> pt[i].x[0] >> pt[i].x[1];
  Get(n);
  Solve(n);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define INF 9999999999999.0
#define D 2      // 空间维数
#define M 100005 // 坐标个数
struct Point {
  double x[D];
} pt[M];
double dis[1 << D][M], minx[1 << D], maxx[1 << D];

// 去掉绝对值后有2^D种可能
void Get(int N) // 取得所有点在指定状态（S）下的“本点有效距离”
{
  int tot = (1 << D);
  for (int s = 0; s < tot; s++) // 遍历所有维数正负状态
  {
    int coe[D];
    for (int i = 0; i < D; i++) // 设定当前状态的具体正负参数
      if (s & (1 << i))
        coe[i] = -1.0;
      else
        coe[i] = 1.0;

    for (int i = 0; i < N;
         i++) // 遍历所有点，确定每个点在当前状态下的“本点有效距离”
    {
      dis[s][i] = 0.0;
      for (int j = 0; j < D; j++)
        dis[s][i] = dis[s][i] + coe[j] * pt[i].x[j];
    }
  }
}
// 取每种可能中的最大差距
void Solve(int N) {
  int tot = (1 << D);
  double tmp, ans;
  for (int s = 0; s < tot; s++) {
    minx[s] = INF;
    maxx[s] = -INF;
    for (int i = 0; i < N; i++) {
      if (minx[s] > dis[s][i])
        minx[s] = dis[s][i];
      if (maxx[s] < dis[s][i])
        maxx[s] = dis[s][i];
    }
  }
  ans = 0.0;
  for (int s = 0; s < tot; s++) {
    tmp = maxx[s] - minx[s];
    if (tmp > ans)
      ans = tmp;
  }

  cout << ans << "\\n";
}

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++)
      scanf("%lf%lf", &pt[i].x[0], &pt[i].x[1]);
    Get(n);
    Solve(n);
  }
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll f(P a, P b) { return abs(a.first - b.first) + abs(a.second - b.second); }

int main() {
  random_device seed_gen;
  mt19937_64 engine(seed_gen());

  ll n;
  cin >> n;
  vector<pair<ll, ll>> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  ll ans = 0;
  ll mi, ma;
  rep(i, n) {
    if (i == 0) {
      mi = p[i].second;
      ma = p[i].second;
    } else {
      mi -= p[i].first - p[i - 1].first;
      ma += p[i].first - p[i - 1].first;
      ans = max(ans, max(abs(p[i].second - mi), abs(p[i].second - ma)));
      mi = min(p[i].second, mi);
      ma = max(p[i].second, ma);
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

ll f(P a, P b) { return abs(a.first - b.first) + abs(a.second - b.second); }

int main() {
  random_device seed_gen;
  mt19937_64 engine(seed_gen());

  ll n;
  cin >> n;
  vector<pair<ll, ll>> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  ll ans = 0;
  rep(i, 1e8) {
    int a = engine() % (ll)n;
    int b = engine() % (ll)n;
    ans = max(ans, f(p[a], p[b]));
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(12), 0);
// int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv
// ./prog.exe") >> 8), 0);
int main() {
  int N;
  cin >> N;
  vector<pair<Int, Int>> P(N);
  for (int i = 0; i < N; i++)
    cin >> P[i].first >> P[i].second;
  sort(begin(P), end(P));
  P.erase(unique(begin(P), end(P)), end(P));
  sort(rbegin(P), rend(P));
  multiset<Int> A, B;
  for (auto [x, y] : P) {
    A.insert(-x - y);
    B.insert(-x + y);
  }
  Int ans = 0;
  for (int i = 0; i < (int)P.size() - 1; i++) {
    auto [x, y] = P[i];
    A.erase(A.find(-x - y));
    B.erase(B.find(-x + y));
    ans = max(ans, x + y + *prev(end(A)));
    ans = max(ans, x - y + *prev(end(B)));
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(12), 0);
// int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv
// ./prog.exe") >> 8), 0);
int main() {
  int N;
  cin >> N;
  vector<pair<Int, Int>> P(N);
  for (int i = 0; i < N; i++)
    cin >> P[i].first >> P[i].second;
  sort(rbegin(P), rend(P));
  P.erase(unique(begin(P), end(P)), end(P));
  set<Int> A, B;
  for (auto [x, y] : P) {
    A.insert(-x - y);
    B.insert(-x + y);
  }
  Int ans = 0;
  for (int i = 0; i < (int)P.size() - 1; i++) {
    auto [x, y] = P[i];
    A.erase(-x - y);
    B.erase(-x + y);
    ans = max(ans, x + y + *prev(end(A)));
    ans = max(ans, x - y + *prev(end(B)));
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int manhattandist(pair<int, int> x, pair<int, int> y) {
  int a = x.first - y.first;
  if (a < 0)
    a = 0 - a;
  int b = x.second - y.second;
  if (b < 0)
    b = 0 - b;
  return a + b;
}

int main() {
  int sma = -2e9, smi = 2e9, bsma = -2e9, bsmi = 2e9;
  int n = 0;
  int ans = 0;
  cin >> n;
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    sma = max(sma, x + y);
    smi = min(smi, x + y);
    bsma = max(bsma, x - y);
    bsmi = min(bsmi, x - y);
  }
  ans = max(sma - smi, bsma - bsmi);
  cout << ans << endl;
  return 0;
}

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 (int i = 0; i < (int)(n); i++)

int manhattandist(pair<int, int> x, pair<int, int> y) {
  int ret = 0;
  int a = x.first - y.first;
  if (a < 0)
    a = 0 - a;
  int b = x.second - y.second;
  if (b < 0)
    b = 0 - b;
  ret = a + b;
  return ret;
}

int main() {
  int n;
  int ans = 0;
  cin >> n;
  vector<P> point(n);
  rep(i, n) cin >> point[i].first >> point[i].second;
  // rep(i, n) cout << point[i].first << ' ' << point[i].second << endl;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = max(manhattandist(point[i], point[j]), ans);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
// #pragma GCC optimize(2)
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ull unsigned long long
#define ll long long
#define rep(i, x, y) for (int i = x; i <= y; i++)
#define mms(x, n) memset(x, n, sizeof(x))
#define mmc(A, tree) memcpy(A, tree, sizeof(tree))
#define eps (1e-8)
#define PI (acos(-1.0))
#define INF (0x3f3f3f3f)
#define mod (ull)(1e9 + 7)
typedef pair<int, int> P;
const int N = 2e5 + 10;
struct Node {
  ll x, y;
} e[N];
ll ans1[N], ans2[N];

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  int n;
  scanf("%d", &n);
  ll ans = 0;
  ll x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &x, &y);
    ans1[i] = (x + y);
    ans2[i] = (x - y);
  }
  sort(ans1 + 1, ans1 + 1 + n);
  sort(ans2 + 1, ans2 + 1 + n);
  ans = max((ll)abs(ans1[1] - ans1[n]), (ll)abs(ans2[1] - ans2[n]));
  printf("%lld", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize(2)
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ull unsigned long long
#define ll long long
#define rep(i, x, y) for (int i = x; i <= y; i++)
#define mms(x, n) memset(x, n, sizeof(x))
#define mmc(A, tree) memcpy(A, tree, sizeof(tree))
#define eps (1e-8)
#define PI (acos(-1.0))
#define INF (0x3f3f3f3f)
#define mod (ull)(1e9 + 7)
typedef pair<int, int> P;
const int n = 2e5 + 10;
ll x[n], y[n];
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  int N;
  scanf("%d", &N);
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (i == j)
        continue;
      ans = max(ans, abs(x[i] - x[j]) + abs(y[i] - y[j]));
    }
  }
  printf("%lld", ans);
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
// #include<cmath>
#include <deque>
#include <stack>
#include <string>
#include <vector>

#define REP(i, a, b) for (int i = (a); i < b; ++i)
#define inf 1e9 + 10
#define MOD 1000000007

using ll = long long;
using ull = unsigned long long;
using namespace std;

inline ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

inline ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0)
    res += m;
  return res;
}

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

  vector<int> x;
  vector<int> y;
  vector<int> z;
  vector<int> w;

  REP(i, 0, n) {
    int a, b;
    cin >> a >> b;
    x.emplace_back(a);
    y.emplace_back(b);
  }

  REP(i, 0, n) {
    z.emplace_back(x[i] + y[i]);
    w.emplace_back(x[i] - y[i]);
  }

  int max_z, min_z, max_w, min_w;

  REP(i, 0, n) {
    if (i == 0) {
      max_z = z[i];
      min_z = z[i];
      max_w = w[i];
      min_w = w[i];
    } else {
      if (max_z < z[i]) {
        max_z = z[i];
      }
      if (min_z > z[i]) {
        min_z = z[i];
      }
      if (max_w < w[i]) {
        max_w = w[i];
      }
      if (min_w > w[i]) {
        min_w = w[i];
      }
    }
  }
  if (max_z - min_z > max_w - min_w) {
    cout << max_z - min_z;
  } else {
    cout << max_w - min_w;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
// #include<cmath>
#include <deque>
#include <stack>
#include <string>
#include <vector>

#define REP(i, a, b) for (int i = (a); i < b; ++i)
#define inf 1e9 + 10
#define MOD 1000000007

using ll = long long;
using ull = unsigned long long;
using namespace std;

inline ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

inline ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0)
    res += m;
  return res;
}

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

  vector<int> x;
  vector<int> y;

  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    x.emplace_back(a);
    y.emplace_back(b);
  }

  int max;
  REP(i, 0, n) {
    REP(j, 0, n) {
      if (i == 0 && j == 0) {
        max = abs(x[i] - x[j]) + abs(y[i] - y[j]);
      }
      if (max < abs(x[i] - x[j]) + abs(y[i] - y[j])) {
        max = abs(x[i] - x[j]) + abs(y[i] - y[j]);
      }
    }
  }

  cout << max;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll dist(pll a, pll b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}

ll optimize(const pll &init, const vector<pll> &v) {
  pll p = init;
  pll q = init;
  ll max_d = 0;
  bool updated = true;
  while (updated) {
    updated = false;
    for (const auto &c : v) {
      ll d_ = dist(p, c);
      if (d_ > max_d) {
        q = c;
        max_d = d_;
        updated = true;
      }
    }
    if (updated)
      p = q;
  }
  return max_d;
}

int main() {
  ll N;
  cin >> N;
  vector<pll> v(N);
  for (int i = 0; i < N; ++i) {
    ll x, y;
    cin >> x >> y;
    v[i] = {x, y};
  }
  ll ans = 0;
  std::mt19937 mt{std::random_device{}()};
  std::uniform_int_distribution<int> d(0, N - 1);
  for (int i = 0; i < 2000; ++i) {
    int r = d(mt);
    ans = max(ans, optimize(v[r], v));
  }
  ans = max(ans, optimize(v[0], v));
  ans = max(ans, optimize(v[N - 1], v));
  for (int i = 0; i < N - 1; ++i) {
    ans = max(ans, dist(v[i], v[i + 1]));
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll dist(pll a, pll b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}

ll optimize(const pll &init, const vector<pll> &v) {
  pll p = v[0];
  pll q = v[0];
  for (int i = 0; i < 300; ++i) {
    for (const auto &c : v) {
      if (dist(p, c) > dist(p, q))
        q = c;
    }
    p = q;
  }
  for (const auto &c : v)
    if (dist(p, c) > dist(p, q))
      q = c;
  return dist(p, q);
}

int main() {
  ll N;
  cin >> N;
  vector<pll> v(N);
  for (int i = 0; i < N; ++i) {
    ll x, y;
    cin >> x >> y;
    v[i] = {x, y};
  }
  ll ans = 0;
  std::mt19937 mt{std::random_device{}()};
  std::uniform_int_distribution<int> d(0, N - 1);
  for (int i = 0; i < 30; ++i) {
    int r = d(mt);
    ans = max(ans, optimize(v[r], v));
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 100;
struct Node {
  ll x, y;
  ll num1, num2;
} p[N];

ll n;
bool cmp1(const Node &a, const Node &b) { return a.num1 < b.num1; }
bool cmp2(const Node &a, const Node &b) { return a.num2 < b.num2; }
int main() {
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> p[i].x >> p[i].y;
    p[i].num1 = p[i].x - p[i].y;
    p[i].num2 = p[i].x + p[i].y;
  }
  ll ans = 0;
  sort(p + 1, p + n + 1, cmp1);
  ans = max(ans, p[n].num1 - p[1].num1);
  sort(p + 1, p + n + 1, cmp2);
  ans = max(ans, p[n].num2 - p[1].num2);
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 100;
struct Node {
  ll x, y;
  ll num1, num2;
} p[N];

ll n;
bool cmp1(const Node &a, const Node &b) { return a.num1 < b.num1; }
bool cmp2(const Node &a, const Node &b) { return a.num2 < b.num2; }
int main() {
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> p[i].x >> p[i].y;
    p[i].num1 = p[i].x - p[i].y;
    p[i].num2 = p[i].x + p[i].y;
  }
  ll ans = 0;
  sort(p + 1, p + n + 1, cmp1);
  ans = max(ans, p[n].num1 - p[1].num1);
  sort(p + 1, p + n + 1, cmp2);
  ans = max(ans, p[n].num2 - p[1].num2);
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long maxAbsValExpr(vector<long long> &x, vector<long long> &y) {
  long long res = 0;
  long long d[4][x.size()];
  for (int i = 0; i < x.size(); i++) {
    d[0][i] = x[i] + y[i];
    d[1][i] = -x[i] - y[i];
    d[2][i] = x[i] - y[i];
    d[3][i] = -x[i] + y[i];
  }
  for (int i = 0; i < 4; i++) {
    sort(d[i], d[i] + x.size());
  }

  for (int i = 0; i < 4; i++) {
    res = max(res, d[i][x.size() - 1] - d[i][0]);
  }
  return res;
}
int main() {
  int n;
  cin >> n;

  vector<long long> x(n);
  vector<long long> y(n);

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

  cout << maxAbsValExpr(x, y);
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  pair<long long, long long> points[n];

  long long max_distance = 0;

  for (int i = 0; i < n; i++)
    cin >> points[i].first >> points[i].second;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      max_distance =
          max(max_distance, abs(points[i].first - points[j].first) +
                                abs(points[i].second - points[j].second));
    }
  }
  cout << max_distance;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define dist(j, i) (abs(dist[0][i] - dist[0][j]) + abs(dist[1][i] - dist[1][j]))
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int maxplusy = -1, maxsuby = -1123456789;
  int minxplusy = 2000000001, minxsuby = 1123456789;
  while (n--) {
    int x, y;
    cin >> x >> y;
    maxplusy = maxplusy < x + y ? x + y : maxplusy;
    maxsuby = maxsuby < x - y ? x - y : maxsuby;
    minxplusy = minxplusy > x + y ? x + y : minxplusy;
    minxsuby = minxsuby > x - y ? x - y : minxsuby;
  }
  cout << max(maxplusy - minxplusy, maxsuby - minxsuby) << '\\n';

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define dist(j, i) (abs(dist[0][i] - dist[0][j]) + abs(dist[1][i] - dist[1][j]))
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int dist[2][200001] = {
      0,
  };
  int max = -1;
  for (int i = 0; i < n; i++) {
    cin >> dist[0][i] >> dist[1][i];
    for (int j = 0; j < i; j++) {
      max = (max < dist(j, i) ? dist(j, i) : max);
    }
  }
  cout << max << '\\n';

  return 0;
}