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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> x;
  vector<int> y;
  int a, b;

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

  a = *max_element(x.begin(), x.end()) - *min_element(x.begin(), x.end());
  b = *max_element(y.begin(), y.end()) - *min_element(y.begin(), y.end());

  cout << max(a, b) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> x;
  vector<int> y;
  int a, b;
  long long int val = 0;

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

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

  cout << val << endl;

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

#include <algorithm>
#include <iostream>
#include <vector>

namespace {}

namespace ABC178 {

class E {
public:
  E() = default;
  ~E() = default;

  void Run() {
    int N = {};
    std::cin >> N;

    long long max_z = LONG_MIN;
    long long min_z = LONG_MAX;
    long long max_w = LONG_MIN;
    long long min_w = LONG_MAX;
    for (int i = 0; i < N; ++i) {
      long long x, y;
      std::cin >> x;
      std::cin >> y;

      if (x + y > max_z)
        max_z = x + y;
      if (x + y < min_z)
        min_z = x + y;
      if (x - y > max_w)
        max_w = x - y;
      if (x - y < min_w)
        min_w = x - y;
    }

    std::cout << std::max(std::abs(max_z - min_z), std::abs(max_w - min_w))
              << std::endl;
  }
};
} // namespace ABC178
int main() {

  ABC178::E prob;
  prob.Run();

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

namespace {}

namespace ABC178 {

class E {
public:
  E() = default;
  ~E() = default;

  void Run() {
    int N = {};
    std::cin >> N;

    std::vector<std::pair<int, int>> p_list = {};
    p_list.reserve(N);

    for (int i = 0; i < N; ++i) {
      int x, y;
      std::cin >> x;
      std::cin >> y;
      p_list.push_back(std::make_pair(x, y));
    }
    std::sort(p_list.begin(), p_list.end(),
              [](const auto &lhs, const auto &rhs) -> bool {
                return lhs.first + lhs.second < rhs.first + rhs.second;
              });
    int max = 0;

    auto N_HALF = N / 2;
    for (int i = 0; i < N_HALF; ++i) {
      auto A = p_list.at(i);

      for (int j = N - 1; j >= N_HALF; --j) {
        auto B = p_list.at(j);
        int d = std::abs(A.first - B.first) + std::abs(A.second - B.second);
        if (d > max)
          max = d;
      }
    }

    std::cout << max << std::endl;
  }
};
} // namespace ABC178

int main() {

  ABC178::E prob;
  prob.Run();

  int a;
  std::cin >> a;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1000000007;
void files() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  ll n;
  cin >> n;
  vector<ll> x(n, 0), y(n, 0);
  for (int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    x[i] = a - b;
    y[i] = a + b;
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  cout << max(x[n - 1] - x[0], y[n - 1] - y[0]);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1000000007;
void files() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  ll n;
  cin >> n;
  vector<pair<ll, ll>> d(n);
  for (ll i = 0; i < n; i++) {
    cin >> d[i].first >> d[i].second;
  }
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      ll dis = abs(d[i].first - d[j].first) + abs(d[i].second - d[j].second);
      ans = max(ans, dis);
    }
  }
  cout << ans;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 200005
#define pb push_back
#define mp make_pair
#define vit vector<int>::iterator
typedef pair<lint, lint> pii;
vector<pii> E;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  lint n, ans = 0, px, py, a, b;
  cin >> n;
  for (lint i = 1; i <= n; i++) {
    cin >> a >> b;
    E.pb(mp(a, b));
  }
  sort(E.begin(), E.end());
  px = E[0].first;
  py = E[0].second;
  for (auto e : E) {
    ans = max(ans, abs(e.first - px) + abs(e.second - py));
    if (e.second < py && (py - e.second) > (e.first - px)) {
      px = e.first;
      py = e.second;
    }
  }

  px = E[0].first;
  py = E[0].second;
  for (auto e : E) {
    ans = max(ans, abs(e.first - px) + abs(e.second - py));
    if (e.second > py && (e.second - py) > (e.first - px)) {
      px = e.first;
      py = e.second;
    }
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<lint, lint> pii;
bool cmp(pii a, pii b) {
  if (a.first != b.first)
    a.first < b.first;
  else
    a.second < b.second;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  lint n, ans = 0, prex, prey, a, b;
  cin >> n;
  vector<pii> E;
  for (lint i = 1; i <= n; i++) {
    cin >> a >> b;
    E.pb({a, b});
  }
  sort(E.begin(), E.end(), cmp);
  prex = E[0].first;
  prey = E[0].second;
  for (lint i = 1; i < n; i++) {
    ans = max(ans, abs(E[i].first - prex) + abs(E[i].second - prey));
    if (E[i].second < prey && (prey - E[i].second) > (E[i].first - prex)) {
      prex = E[i].first;
      prey = E[i].second;
    }
  }

  prex = E[0].first;
  prey = E[0].second;
  for (lint i = 1; i < n; i++) {
    ans = max(ans, abs(E[i].first - prex) + abs(E[i].second - prey));
    if (E[i].second > prey && (E[i].second - prey) > (E[i].first - prex)) {
      prex = E[i].first;
      prey = E[i].second;
    }
  }
  cout << ans;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define oo 1000000007
#define maxN 200007
using namespace std;

int x[maxN], y[maxN];
pair<int, int> add[maxN], sub[maxN];
int ans = 0;

void findAns(int best_x, int best_y, int n) {
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, (int)abs(best_x - x[i]) + (int)abs(best_y - y[i]));
  }
}

int main() {

  int n;
  cin >> n;

  for (int i = 1; i <= n; ++i) {
    cin >> x[i] >> y[i];
    add[i] = make_pair(x[i] + y[i], i);
    sub[i] = make_pair(x[i] - y[i], i);
  }

  sort(add + 1, add + n + 1);
  sort(sub + 1, sub + n + 1);

  int best_x, best_y;
  best_x = x[add[1].second], best_y = y[add[1].second];
  findAns(best_x, best_y, n);
  best_x = x[add[n].second], best_y = y[add[n].second];
  findAns(best_x, best_y, n);
  best_x = x[sub[1].second], best_y = y[sub[1].second];
  findAns(best_x, best_y, n);
  best_x = x[sub[n].second], best_y = y[sub[n].second];
  findAns(best_x, best_y, n);

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define oo 1000000007
#define maxN 200007
using namespace std;

int x[maxN], y[maxN];
pair<int, int> add[maxN], sub[maxN];
int ans = 0;

void findAns(int best_x, int best_y, int n) {
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, (int)abs(best_x - x[i]) + (int)abs(best_y - y[i]));
  }
}

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

  for (int i = 1; i <= n; ++i) {
    cin >> x[i] >> y[i];
    add[i] = make_pair(x[i] + y[i], i);
    sub[i] = make_pair(x[i] - y[i], i);
  }

  sort(add + 1, add + n + 1);
  sort(sub + 1, sub + n + 1);

  for (int i = 1; i <= n; ++i) {
    int best_x, best_y;
    best_x = x[add[1].second], best_y = y[add[1].second];
    findAns(best_x, best_y, n);
    best_x = x[add[n].second], best_y = y[add[n].second];
    findAns(best_x, best_y, n);
    best_x = x[sub[1].second], best_y = y[sub[1].second];
    findAns(best_x, best_y, n);
    best_x = x[sub[n].second], best_y = y[sub[n].second];
    findAns(best_x, best_y, n);
  }

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

#include <bits/stdc++.h>

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, N) for (int i = 1; i <= N; i++)
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;

// status unsolved
bool cmp1(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.first > p2.first;
}
bool cmp2(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.second > p2.second;
}
long long getabs(pair<long long, long long> p1, pair<long long, long long> p2) {
  return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}
long long solve_simple(vector<pair<long long, long long>> p) {
  long long ret = 0;
  for (int i = 0; i < p.size() - 1; i++) {
    for (int k = i; k < p.size(); k++) {
      ret = max(getabs(p[i], p[k]), ret);
    }
  }
  return ret;
}
long long solve(vector<pair<long long, long long>> p) {
  vector<long long> z;
  vector<long long> w;
  for (int i = 0; i < p.size(); i++) {
    z.push_back(p[i].first + p[i].second);
    w.push_back(p[i].first - p[i].second);
  }
  sort(z.begin(), z.end());
  sort(w.begin(), w.end());
  return max(z[p.size() - 1] - z[0], w[p.size() - 1] - w[0]);
}

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

  vector<pair<long long, long long>> point(n);

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

  // cout<<solve_simple(point)<<endl;

  cout << solve(point) << endl;
  return 0;
}
/*


*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, N) for (int i = 1; i <= N; i++)
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;

// status unsolved
bool cmp1(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.first > p2.first;
}
bool cmp2(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.second > p2.second;
}
long long getabs(pair<long long, long long> p1, pair<long long, long long> p2) {
  return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}
long long solve_simple(vector<pair<long long, long long>> p) {
  long long ret = 0;
  for (int i = 0; i < p.size() - 1; i++) {
    for (int k = i; k < p.size(); k++) {
      ret = max(getabs(p[i], p[k]), ret);
    }
  }
  return ret;
}

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

  vector<pair<long long, long long>> point(n);

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

  cout << solve_simple(point) << endl;
  // sort(point.begin(),point.end(),cmp1);
  // long long ans=0;
  // rep(i,n){
  //     //cout<<point[i].first<<" "<<point[i].second<<endl;
  //     long long
  //     tmp=max(getabs(point[0],point[i]),getabs(point[n-1],point[i]));
  //     ans=max(tmp,ans);
  // }

  // sort(point.begin(),point.end(),cmp2);
  // rep(i,n){
  //     //cout<<point[i].first<<" "<<point[i].second<<endl;
  //     long long
  //     tmp=max(getabs(point[0],point[i]),getabs(point[n-1],point[i]));
  //     ans=max(tmp,ans);
  // }
  // cout<<ans<<endl;
  return 0;
}
/*


*/
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define Imposter                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
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;
#define f(n) for (ll i = 0; i < n; i++)
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define input(arr, n)                                                          \\
  for (ll i1 = 0; i1 < n; i1++)                                                \\
  cin >> arr[i1]
#define endl "\\n"
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(), x.end()
ll maxAbsValExpr(vector<ll> &x, vector<ll> &y) {
  ll res = 0, n = x.size(), smallest, cur;
  for (int p : {1, -1}) {
    for (int q : {1, -1}) {
      smallest = p * x[0] + q * y[0] + 0;
      for (int i = 1; i < n; ++i) {
        cur = p * x[i] + q * y[i];
        res = max(res, cur - smallest);
        smallest = min(smallest, cur);
      }
    }
  }
  return res;
}
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  Imposter

      int t = 1;
  // cin>>t;
  while (t--) {
    int n;
    cin >> n;
    vll a, b;
    f(n) {
      ll x, y;
      cin >> x >> y;
      a.pb(x);
      b.pb(y);
    }
    cout << maxAbsValExpr(a, b) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int 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;
}

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[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: Runtime Error

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

#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define pii pair<int, int>

int N;
int X[200010], Y[200010];

signed main() {
  cin >> N;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    X[i] = x + y;
    Y[i] = x - y;
  }

  sort(X, X + N);
  sort(Y, Y + N);

  cout << max(X[N - 1] - X[0], Y[N - 1] - Y[0]) << endl;

  return 0;
}


Error: 0

Fixed submission:

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

#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define pii pair<int, int>

int N;
int X[100010], Y[100010];

signed main() {
  cin >> N;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    X[i] = x + y;
    Y[i] = x - y;
  }

  sort(X, X + N);
  sort(Y, Y + N);

  cout << max(X[N - 1] - X[0], Y[N - 1] - Y[0]) << endl;

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

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
using namespace std;

int32_t main() {

  fast int n;
  cin >> n;

  vector<int> x(n);
  vector<int> y(n);
  int a, b, c, d;
  a = c = INT_MIN;
  b = d = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    a = max(a, x[i] + y[i]);
    b = min(b, x[i] + y[i]);
    c = max(c, x[i] - y[i]);
    d = min(d, x[i] - y[i]);
  }
  vector<pair<int, int>> as, bs, cs, ds;
  for (int i = 0; i < n; i++) {
    if (x[i] + y[i] == a && as.empty()) {
      as.push_back({x[i], y[i]});
    }
    if (x[i] + y[i] == b && bs.empty()) {
      bs.push_back({x[i], y[i]});
    }
    if (x[i] - y[i] == c && cs.empty()) {
      cs.push_back({x[i], y[i]});
    }
    if (x[i] - y[i] == d && ds.empty()) {
      ds.push_back({x[i], y[i]});
    }
  }
  int ans = INT_MIN;
  for (auto &i : as) {
    for (auto &j : bs) {
      ans = max(ans, abs(i.first - j.first) + abs(i.second - j.second));
    }
  }
  for (auto &i : cs) {
    for (auto &j : ds) {
      ans = max(ans, abs(i.first - j.first) + abs(i.second - j.second));
    }
  }
  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
using namespace std;

int32_t main() {

  fast int n;
  cin >> n;

  vector<int> x(n);
  vector<int> y(n);
  int a, b, c, d;
  a = c = INT_MIN;
  b = d = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    a = max(a, x[i] + y[i]);
    b = min(b, x[i] + y[i]);
    c = max(c, x[i] - y[i]);
    d = min(d, x[i] - y[i]);
  }
  vector<pair<int, int>> as, bs, cs, ds;
  for (int i = 0; i < n; i++) {
    if (x[i] + y[i] == a) {
      as.push_back({x[i], y[i]});
    }
    if (x[i] + y[i] == b) {
      bs.push_back({x[i], y[i]});
    }
    if (x[i] - y[i] == c) {
      cs.push_back({x[i], y[i]});
    }
    if (x[i] - y[i] == d) {
      ds.push_back({x[i], y[i]});
    }
  }
  int ans = INT_MIN;
  for (auto &i : as) {
    for (auto &j : bs) {
      ans = max(ans, abs(i.first - j.first) + abs(i.second - j.second));
    }
  }
  for (auto &i : cs) {
    for (auto &j : ds) {
      ans = max(ans, abs(i.first - j.first) + abs(i.second - j.second));
    }
  }
  cout << ans;

  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> u(N), v(N);
  int x, y;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    u.at(i) = x - y;
    v.at(i) = x + y;
  }
  sort(u.begin(), u.end());
  sort(v.begin(), v.end());
  cout << max(u.at(N - 1) - u.at(0), v.at(N - 1) - v.at(0));
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++)
    cin >> x.at(i) >> y.at(i);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int distance = max(x.at(i), x.at(j)) - min(x.at(i), x.at(j)) +
                     max(y.at(i), y.at(j)) - min(y.at(i), y.at(j));
      if (ans < distance)
        ans = distance;
    }
  }
  cout << ans;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 400000 + 10;
const int dem = 2; // 维数
const double INF = (1e200);

struct Point {
  double x[dem];
} p[maxn];

int n;
double minx[1 << dem], maxx[1 << dem];

long long solve() {
  int tmp = 1 << dem;

  for (int i = 0; i < tmp; i++) {
    minx[i] = INF;
    maxx[i] = -INF;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tmp; j++) {
      int t = j;
      double s = 0;
      for (int k = 0; k < dem; k++) {
        if (t & 1)
          s += p[i].x[k];
        else
          s -= p[i].x[k];
        t >>= 1;
      }
      if (maxx[j] < s)
        maxx[j] = s;
      if (minx[j] > s)
        minx[j] = s;
    }
  }

  double ans = -INF;
  for (int i = 0; i < tmp; i++) {
    if (maxx[i] - minx[i] > ans)
      ans = maxx[i] - minx[i];
  }

  return ans;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < dem; j++) {
      scanf("%lf", &p[i].x[j]);
    }
  }
  cout << solve() << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 100000 + 10;
const int dem = 2; // 维数
const double INF = (1e200);

struct Point {
  double x[dem];
} p[maxn];

int n;
double minx[1 << dem], maxx[1 << dem];

long long solve() {
  int tmp = 1 << dem;

  for (int i = 0; i < tmp; i++) {
    minx[i] = INF;
    maxx[i] = -INF;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tmp; j++) {
      int t = j;
      double s = 0;
      for (int k = 0; k < dem; k++) {
        if (t & 1)
          s += p[i].x[k];
        else
          s -= p[i].x[k];
        t >>= 1;
      }
      if (maxx[j] < s)
        maxx[j] = s;
      if (minx[j] > s)
        minx[j] = s;
    }
  }

  double ans = -INF;
  for (int i = 0; i < tmp; i++) {
    if (maxx[i] - minx[i] > ans)
      ans = maxx[i] - minx[i];
  }

  return ans;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < dem; j++) {
      scanf("%lf", &p[i].x[j]);
    }
  }
  cout << solve() << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll q;
  cin >> q;
  ll si = q;
  vector<pair<ll, ll>> v;
  while (q--) {
    ll n, m;
    cin >> n >> m;
    v.push_back({n, m});
  }
  vector<ll> a, b;
  for (int i = 0; i < si; 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());
  ll ans = abs(a[si - 1] - a[0]);
  ans = max(ans, b[si - 1] - b[0]);
  cout << ans;
}

Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll q;
  cin >> q;
  vector<pair<ll, ll>> v;
  while (q--) {
    ll n, m;
    cin >> n >> m;
    v.push_back(make_pair(n, m));
  }
  sort(v.begin(), v.end());
  ll ans = -1e18;
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = i + 1; j < v.size(); j++) {
      ll tm = abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second);
      ans = max(ans, tm);
    }
  }
  cout << ans;
}