alexjercan/bugnet huggingface dataset:
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
ll pts[200005][6] = {0};

ll mnht(ll pt[200005][6], 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;
}
/*
10
-70 -64 -6 -56 64 61 -57 16 48 -98
*/
ll max_cmb(ll cmbn[6], ll pt[200005][6], 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;
}

int32_t main() {
  int n, d = 2;
  cin >> n;

  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[6] = {0};
    for (int dig = 0; dig < d; dig++) {
      if (j & 1 << dig)
        cmbn[dig] = 1;
      // cout<<cmbn[dig]<<" ";
    }
    // cout<<endl;
    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 <bits/stdc++.h>
#define int int64_t
using namespace std;

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

ll mnht(ll pt[100005][6], 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;
}
/*
10
-70 -64 -6 -56 64 61 -57 16 48 -98
*/
ll max_cmb(ll cmbn[6], ll pt[100005][6], 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;
}

int32_t main() {
  int n, d = 2;
  cin >> n;

  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[6] = {0};
    for (int dig = 0; dig < d; dig++) {
      if (j & 1 << dig)
        cmbn[dig] = 1;
      // cout<<cmbn[dig]<<" ";
    }
    // cout<<endl;
    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>

using namespace std;

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

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  cout << max(x[n - 1] - x[0], y[n - 1] - y[0]);
  return 0;
}

Error: TLE

Fixed submission:

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

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

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};

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

  int n;
  cin >> n;
  vector<int> a, b;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a.push_back(x + y);
    b.push_back(x - y);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cout << max(a[n - 1] - a[0], b[n - 1] - b[0]) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define rrep(i, n) for (int(i) = 1; i <= (n); i++)
#define REP(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\\n"
#define yorn(f) puts((f) ? "Yes" : "No")
#define YORN(f) puts((f) ? "YES" : "NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int mod(int a, int b) { return (a + b - 1) / b; };
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};

struct poi {
  int x, y;
  poi operator-(poi p) { return {x - p.x, y - p.y}; }
  bool operator<(poi p) const { return tie(x, y) < tie(p.x, p.y); }
  int cross(poi p) { return x * p.y - y * p.x; }
};
int xmul(poi a, poi b, poi c) { return (b - a).cross(c - a); }

using vp = vector<poi>;
vp convex(vp v) {
  sort(v.begin(), v.end());
  vp r;
  for (int i = 0; i < v.size(); i++) {
    while (r.size() > 1 && xmul(*++r.rbegin(), v[i], *r.rbegin()) > 0)
      r.pop_back();
    r.push_back(v[i]);
  }
  int d = r.size();
  for (int i = (int)v.size() - 2; i >= 0; i--) {
    while (r.size() > d && xmul(*++r.rbegin(), v[i], *r.rbegin()) > 0)
      r.pop_back();
    if (i != 0)
      r.push_back(v[i]);
  }
  return r;
}

signed main() {
  ios ::sync_with_stdio(false);
  int n;
  cin >> n;
  vp v;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }
  v = convex(v);

  // rotate(v.begin(), min_element(v.begin(), v.end(), [](poi a, poi b) {
  // 	return tie(a.y, a.x) < tie(b.y, b.x);
  // }), v.end());

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

#include "bits/stdc++.h"
// #include"atcoder.h"
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
const ll inf = ll(1e18) + 1;
const ll mod = 1000000007;

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

  vector<ll> z(n + 5);
  vector<ll> w(n + 5);

  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    z[i] = x + y;
    w[i] = x - y;
  }

  ll result = 0;
  ll z_max = z[0];
  ll z_min = z[0];
  ll w_max = w[0];
  ll w_min = w[0];

  for (int i = 1; i < n; i++) {
    if (z[i] >= z_max) {
      z_max = z[i];
    } else if (z[i] <= z_min) {
      z_min = z[i];
    }

    if (w[i] >= w_max) {
      w_max = w[i];
    } else if (w[i] <= w_min) {
      w_min = w[i];
    }
  }

  result = max(z_max - z_min, w_max - w_min);

  cout << result << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
const ll inf = ll(1e18) + 1;
const ll mod = 1000000007;

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

  vector<ll> x(n + 5);
  vector<ll> y(n + 5);

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

  ll result = 0;

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

  cout << result << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define ll long long
#define pb push_back
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define vi vector<int>
#define fr(a, b) for (int i = a; i <= b; i++)
#define inf 1e18
#define mod 1000000007

int main() {

  fast;
  ll n;
  cin >> n;
  ll a[n + 1];
  ll b[n + 1];
  for (int i = 0; i < n; i++) {
    ll x, y;
    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]) << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);
#define ll long long int
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (long int i = a; i >= b; i--)
#define l long int
#define endl '\\n'
#define pb push_back
#define pf pop.front()
using namespace std;

void solve() {
  l n;
  cin >> n;
  ll a[n], b[n];

  f(i, 0, n) { cin >> a[i] >> b[i]; }
  ll mx = LLONG_MIN;
  for (l i = 0; i < n - 1; i++)
    for (ll j = i + 1; j < n; j++)
      mx = max(mx, abs(a[i] - a[j]) + abs(b[i] - b[j]));

  cout << mx << endl;
}

int32_t main() {
  FAST l T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define int long long
#define ar array<int, 2>
#define inf 1000000000000000000
int mod = 1e9 + 7;
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a, int b) { return (a > b) ? a : b; }
int fp(int a, int b) {
  if (b == 0)
    return 1;
  int x = fp(a, b / 2);
  x = (x * x) % mod;
  if (b & 1)
    x = (x * a) % mod;
  return x;
}

const int N = 2e5 + 5;

void solve() {
  int n, x, y;
  cin >> n;
  vector<int> tmp(1ll << 2, -inf);
  int ans = -inf;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    for (int j = 0; j < (1ll << 2); j++) {
      if (tmp[j] == -inf)
        break;
      int z = tmp[j];
      if (j & 1)
        z -= y;
      else
        z += y;
      if ((j >> 1) & 1)
        z -= x;
      else
        z += x;
      ans = max(ans, z);
    }

    for (int j = 0; j < (1ll << 2); j++) {
      int z = 0;
      if (j & 1)
        z += y;
      else
        z -= y;
      if ((j >> 1) & 1)
        z += x;
      else
        z -= x;
      tmp[j] = max(tmp[j], z);
      // cout<<tmp[j]<<endl;
    }
  }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  int t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define int long long
#define ar array<int, 2>
#define inf 1000000000000000000
int mod = 1e9 + 7;
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a, int b) { return (a > b) ? a : b; }
int fp(int a, int b) {
  if (b == 0)
    return 1;
  int x = fp(a, b / 2);
  x = (x * x) % mod;
  if (b & 1)
    x = (x * a) % mod;
  return x;
}

const int N = 2e5 + 5;

void solve() {
  int n, x, y;
  cin >> n;
  vector<int> tmp(1ll << 2, -inf);
  int ans = -inf;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    for (int j = 0; j < (1ll << 2); j++) {
      if (tmp[i] == -inf)
        break;
      int z = tmp[j];
      if (j & 1)
        z -= y;
      else
        z += y;
      if ((j >> 1) & 1)
        z -= x;
      else
        z += x;
      ans = max(ans, z);
    }

    for (int j = 0; j < (1ll << 2); j++) {
      int z = 0;
      if (j & 1)
        z += y;
      else
        z -= y;
      if ((j >> 1) & 1)
        z += x;
      else
        z -= x;
      tmp[j] = max(tmp[j], z);
      // cout<<tmp[j]<<endl;
    }
  }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  int t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

#define ll long long
#define all(v) v.begin(), v.end()
#define bootstrap ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

void solve() {
  int N;
  cin >> N;
  vector<int> A, B;
  // transform for Mannhatan distance ,so no need for pair-wise comparison.
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    A.push_back(a + b);
    B.push_back(a - b);
  }
  sort(all(A));
  sort(all(B));
  // rep(k, N) {
  //     cout << B[k] << endl;
  // }
  int res = max(A[N - 1] - A[0], B[N - 1] - B[0]);
  cout << res << endl;
}

int main() { bootstrap solve(); }


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define ll long long
#define all(v) v.begin(), v.end()
#define bootstrap ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// custom hash can be a standalone function object:
struct MyHash {
  std::size_t operator()(pair<long, long> const &p) const noexcept {
    std::size_t h1 = std::hash<long>{}(p.first);
    std::size_t h2 = std::hash<long>{}(p.second);
    return h1 ^ (h2 << 1); // or use boost::hash_combine (see Discussion)
  }
};

vector<pair<long, long>> getFurthest(vector<pair<long, long>> &kvs) {
  long max = 0;
  long dis;
  vector<pair<long, long>> ret;
  for (unsigned int i = 1; i < kvs.size(); ++i) {
    for (int j = 0; j < i; ++j) {
      dis =
          abs(kvs[i].first - kvs[j].first) + abs(kvs[i].second - kvs[j].second);
      if (dis == max) {
        ret.push_back(kvs[i]);
        ret.push_back(kvs[j]);
      }
      if (dis > max) {
        max = dis;
        ret.clear();
        ret.push_back(kvs[i]);
        ret.push_back(kvs[j]);
      }
    }
  }
  return ret;
}

void solve() {
  // quantization
  long num;
  cin >> num;
  unordered_multimap<pair<long, long>, pair<long, long>, MyHash> kvs;
  // maybe need recursive
  long q = 100000;
  long x, y;
  for (int i = 0; i < num; i++) {
    cin >> x >> y;
    kvs.emplace(pair<long, long>(x / q, y / q), pair<long, long>(x, y));
  }
  vector<pair<long, long>> keys;
  for (auto &[k, v] : kvs) {
    keys.push_back(k);
  }
  auto candidates = getFurthest(keys);
  vector<pair<long, long>> data;
  for (const auto &key : keys) {
    auto its = kvs.equal_range(key);
    for_each(its.first, its.second,
             [&data](pair<const pair<long, long>, pair<long, long>> datum) {
               data.push_back(datum.second);
             });
  }
  auto res = getFurthest(data);
  cout << abs(res[0].first - res[1].first) + abs(res[0].second - res[1].second);
}

int main() { bootstrap solve(); }
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>

#define rep2(x, fr, to) for (int x = (fr); x < (to); x++)
#define rep(x, to) for (int x = 0; x < (to); x++)
#define repr(x, fr, to) for (int x = (fr); x >= (to); x--)
#define all(c) c.begin(), c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<ll> VL;
const int MD = 1e9 + 7;
void dbg() { cerr << "\\n"; }
template <class F, class... S> void dbg(const F &f, const S &...s) {
  cerr << f << ": ";
  dbg(s...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;

  ll lm[] = {MD, -MD, MD, -MD};

  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    lm[0] = min(lm[0], x + y);
    lm[1] = max(lm[1], x + y);
    lm[2] = min(lm[2], x - y);
    lm[3] = max(lm[3], x - y);
  }
  ll ans = max(lm[1] - lm[0], lm[3] - lm[2]);
  cout << ans << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define rep2(x, fr, to) for (int x = (fr); x < (to); x++)
#define rep(x, to) for (int x = 0; x < (to); x++)
#define repr(x, fr, to) for (int x = (fr); x >= (to); x--)
#define all(c) c.begin(), c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<ll> VL;
const int MD = 1e9 + 7;
void dbg() { cerr << "\\n"; }
template <class F, class... S> void dbg(const F &f, const S &...s) {
  cerr << f << ": ";
  dbg(s...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) { cin >> x[i] >> y[i]; }
  ll ans = 0;
  rep(i, n) {
    rep2(j, i + 1, n) {
      ll w = abs(x[j] - x[i]) + abs(y[j] - y[i]);
      ans = max(ans, w);
    }
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
using ll = long long;

int main() {
  ll i, N, x, y, maxw = -2e9, maxz = -2e9, minw = 2e9, minz = 2e9;
  cin >> N;
  for (i = 0; i < N; ++i) {
    cin >> x >> y;
    maxw = max(maxw, x + y);
    minw = min(minw, x + y);
    maxz = max(maxz, x - y);
    minz = min(minz, x - y);
  }
  cout << max(maxw - minw, maxz - minz) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll N, i, x, y, ans = 0;
  cin >> N;
  vector<pair<ll, ll>> v;
  for (i = 0; i < N; ++i) {
    cin >> x >> y;
    v.push_back({x, y});
    for (auto &e : v) {
      ans = max(ans, abs(e.first - x) + abs(e.second - y));
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define VSORT(v) sort(v.begin(), v.end());
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
using namespace std;
typedef long long ll;
const double PI = acos(-1);
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int di[] = {-1, 0, 1, 0}, dj[] = {0, -1, 0, 1};
const int INF = 99999999;
const ll LINF = 9999999999999;

int main() {
  int n;
  cin >> n;
  vector<ll> z(n), w(n);
  ll maxz = 0, minz = LINF, maxw = 0, minw = INF;
  REP(i, n) {
    ll x, y;
    cin >> x >> y;
    z[i] = x + y;
    w[i] = x - y;
  }
  sort(z.begin(), z.end());
  sort(w.begin(), w.end());

  cout << max(z.back() - z[0], w.back() - w[0]);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n)                                                              \\
  for (ll i = 0; i < (n); ++i)                                                 \\
    ;
#define FOR(i, m, n)                                                           \\
  for (int i = (m); i < (n); i++)                                              \\
    ;
#define VSORT(v) sort(v.begin(), v.end());
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
using namespace std;
typedef long long ll;
const double PI = acos(-1);
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int di[] = {-1, 0, 1, 0}, dj[] = {0, -1, 0, 1};
const int INF = 99999999;
const ll LINF = 9999999999999;

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

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

#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie();                                                                   \\
  cout.tie(0)
#pragma GCC optimize(2)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int N = 200010;
int d1[N], d2[N], n;
int main() {
  IO;
  int T = 1;
  // cin>>T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      int x, y;
      cin >> x >> y;
      d1[i] = x + y;
      d2[i] = x - y;
    }
    sort(d1 + 1, d1 + 1 + n);
    sort(d2 + 1, d2 + 1 + n);
    cout << max(d1[n] - d1[1], d2[n] - d2[1]) << '\\n';
  }
  return 0;
}


Error: TLE

Fixed submission:

#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie();                                                                   \\
  cout.tie(0)
#pragma GCC optimize(2)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int N = 200010;
const ll mod = 1e9 + 7;
pii p[N], tmp[N];
int n;
int calc(pii a, pii b) { return abs(a.x - b.x) + abs(a.y - b.y); }
int work(int l, int r) {
  if (l == r)
    return 0;
  int mid = l + r >> 1;

  int res = max(work(l, mid), work(mid + 1, r));
  for (int i = l; i <= mid; i++)
    for (int j = mid + 1; j <= r; j++)
      res = max(res, calc(p[i], p[j]));

  return res;
}
int main() {
  IO;
  int T = 1;
  // cin>>T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; i++)
      cin >> p[i].x >> p[i].y;
    sort(p + 1, p + 1 + n);
    cout << work(1, n) << '\\n';
  }
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vl = vector<ll>;

#define rep(i, ns, ne) for (ll i = ns; i < ne; ++i)

ll N;
Vl a;
Vl b;

void input() {
  cin >> N;
  a.resize(N);
  b.resize(N);
  int x, y;
  rep(i, 0, N) {
    cin >> x >> y;
    a[i] = x + y;
    b[i] = x - y;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
}

void solve() {
  cout << max(a.back() - a.front(), b.back() - b.front()) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  solve();
  getchar();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vl = vector<ll>;

#define rep(i, ns, ne) for (ll i = ns; i < ne; ++i)

ll N;
Vl X;
Vl Y;

void input() {
  int tmp;
  cin >> N;
  X.resize(N);
  Y.resize(N);
  rep(i, 0, N) { cin >> X[i] >> Y[i]; }
}

void solve() {
  ll ans = 0;
  ll tmp;
  rep(i, 0, N - 1) {
    rep(j, i + 1, N) {
      tmp = abs(X[i] - X[j]) + abs(Y[i] - Y[j]);
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  solve();
  getchar();
  return 0;
}