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

#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define N 200060
#define ll long long
using namespace std;

map<ll, int> mp[33];
typedef map<ll, int>::iterator iter;
int seq[N][5];
int n, m;
void del(int pos, int val) {
  iter t1 = mp[pos].find(val);
  t1->second--;
  if (t1->second == 0)
    mp[pos].erase(t1);
  return;
}
int mm;
int myabs(int x) { return x < 0 ? -x : x; }
ll get_ans() {
  ll res = 0;
  for (int i = 0; i < mm; i++) {
    iter l = mp[i].begin();
    iter r = mp[i].end();
    r--;
    ll tmp = myabs((l->first) - (r->first));
    if (tmp > res)
      res = tmp;
  }
  return res;
}
void dfs(int deep, int val, int root, int pos, int id) {
  if (deep >= m) {
    if (id == 0) {
      mp[root][val]++;
    } else {
      del(root, val);
    }
    return;
  }
  dfs(deep + 1, val + seq[pos][deep], root * 2, pos, id);
  dfs(deep + 1, val - seq[pos][deep], root * 2 + 1, pos, id);
  return;
}
signed main() {
  scanf("%d", &n);
  m = 2;
  mm = 1 << m;
  for (int i = 0; i < mm; i++)
    mp[i].clear();

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++)
      scanf("%d", &seq[i][j]);
    dfs(0, 0, 0, i, 0);
    //  puts("d");
  }
  printf("%lld\\n", get_ans());
}

Error: 0

Fixed submission:

#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define N 60060
#define ll long long
using namespace std;

map<ll, int> mp[33];
typedef map<ll, int>::iterator iter;
int seq[N][5];
int n, m;
void del(int pos, int val) {
  iter t1 = mp[pos].find(val);
  t1->second--;
  if (t1->second == 0)
    mp[pos].erase(t1);
  return;
}
int mm;
int myabs(int x) { return x < 0 ? -x : x; }
ll get_ans() {
  ll res = 0;
  for (int i = 0; i < mm; i++) {
    iter l = mp[i].begin();
    iter r = mp[i].end();
    r--;
    ll tmp = myabs((l->first) - (r->first));
    if (tmp > res)
      res = tmp;
  }
  return res;
}
void dfs(int deep, int val, int root, int pos, int id) {
  if (deep >= m) {
    if (id == 0) {
      mp[root][val]++;
    } else {
      del(root, val);
    }
    return;
  }
  dfs(deep + 1, val + seq[pos][deep], root * 2, pos, id);
  dfs(deep + 1, val - seq[pos][deep], root * 2 + 1, pos, id);
  return;
}
signed main() {
  scanf("%d", &n);
  m = 2;
  mm = 1 << m;
  for (int i = 0; i < mm; i++)
    mp[i].clear();

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++)
      scanf("%d", &seq[i][j]);
    dfs(0, 0, 0, i, 0);
    //  puts("d");
  }
  printf("%lld\\n", get_ans());
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define inf 1e200
typedef long long ll;
ll a[200003][2];
ll n;
ll GetManhattan(ll p[][2], ll n, ll dem) {
  ll ans = 0, Min, Max;
  ll i, j, k;
  for (i = 0; i < (1 << (dem)); i++) { // 用二进制形式遍历所有可能的运算情况
    Min = inf, Max = -inf;
    for (j = 0; j < n; j++) { // 遍历每一个点
      ll sum = 0;
      for (k = 0; k < 2; k++) { // 因为是五维的，所以有4个运算符
        // 提取当前运算符
        ll t = i & 1 << k; // 1为+，0为-
        if (t)
          sum += p[j][k];
        else
          sum -= p[j][k];
      }
      if (sum > Max)
        Max = sum;
      if (sum < Min)
        Min = sum;
    }
    if (Max - Min > ans)
      ans = Max - Min;
  }
  return ans;
}
#pragma warning(disable : 4996)
int main() {
  scanf("%d", &n);
  {
    for (ll i = 0; i < n; i++)
      for (ll j = 0; j < 2; j++)
        scanf("%lld", &a[i][j]);
    ll ans = GetManhattan(a, n, 2);
    printf("%lld\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define inf 1e200
typedef long long ll;
ll a[100001][2];
ll n;
ll GetManhattan(ll p[][2], ll n, ll dem) {
  ll ans = 0, Min, Max;
  ll i, j, k;
  for (i = 0; i < (1 << (dem)); i++) { // 用二进制形式遍历所有可能的运算情况
    Min = inf, Max = -inf;
    for (j = 0; j < n; j++) { // 遍历每一个点
      ll sum = 0;
      for (k = 0; k < 2; k++) { // 因为是五维的，所以有4个运算符
        // 提取当前运算符
        ll t = i & 1 << k; // 1为+，0为-
        if (t)
          sum += p[j][k];
        else
          sum -= p[j][k];
      }
      if (sum > Max)
        Max = sum;
      if (sum < Min)
        Min = sum;
    }
    if (Max - Min > ans)
      ans = Max - Min;
  }
  return ans;
}
#pragma warning(disable : 4996)
int main() {
  scanf("%d", &n);
  {
    for (ll i = 0; i < n; i++)
      for (ll j = 0; j < 2; j++)
        scanf("%lld", &a[i][j]);
    ll ans = GetManhattan(a, n, 2);
    printf("%lld\\n", ans);
  }
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i < (b); i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it, c)                                                         \\
  for (__typeof((c).begin()) it = c.begin(); it != c.end(); it++)
// #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read() {
  ll x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -f;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c - '0');
  return x * f;
}
inline void out(int x) {
  if (x >= 10)
    out(x / 10);
  putchar(x % 10 + '0');
}
int n;
ll x[202020], y[202020], a[202020], b[202020];
int main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  cin >> n;
  fo(i, 0, n) {
    cin >> x[i] >> y[i];
    a[i] = x[i] + y[i];
    b[i] = 1e9 - x[i] + y[i];
  }
  sort(a, a + n);
  sort(b, b + n);
  cout << max(a[n - 1] - a[0], b[n - 1] - b[0]) << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i < (b); i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it, c)                                                         \\
  for (__typeof((c).begin()) it = c.begin(); it != c.end(); it++)
// #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read() {
  ll x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -f;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c - '0');
  return x * f;
}
inline void out(int x) {
  if (x >= 10)
    out(x / 10);
  putchar(x % 10 + '0');
}
int n, a[1010101], cnt[1010101];
bool pr(int x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0)
      return 0;
  return 1;
}
int main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  cin >> n;
  fo(i, 0, n) cin >> a[i];
  bool ok = 0;
  fo(i, 2, 1000) if (pr(i)) {
    fo(j, 0, 1000001) cnt[j] = 0;
    int g = 0, k = 0;
    fo(j, 0, n) if (a[j] % i == 0) {
      g++;
      cnt[a[j] / i]++;
      k = max(k, cnt[a[j] / i]);
    }
    g = max(g, k);
    if (g == n) {
      cout << "not coprime\\n";
      return 0;
    }
    if (g > 1)
      ok = 1;
  }
  if (ok && n != 2)
    cout << "setwise coprime\\n";
  else
    cout << "pairwise coprime\\n";
  return 0;
}
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)
using P = pair<ll, ll>;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    a.at(i) = x + y;
    b.at(i) = x - y;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ll ans = max(a.back() - a.front(), b.back() - b.front());
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  vector<P> p(n);
  rep(i, n) cin >> p.at(i).first >> p.at(i).second;
  ll ans = -1;
  for (ll i = 0; i < n - 1; ++i) {
    ll xi = p.at(i).first;
    ll yi = p.at(i).second;
    for (ll j = i + 1; j < n; ++j) {
      ll xj = p.at(j).first;
      ll yj = p.at(j).second;
      ll dis = abs(xi - xj) + abs(yi - yj);
      ans = max(ans, dis);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 2e5 + 5;
struct node {
  int x, y, px, py;
} p[N];
bool cmp(node a, node b) { return a.px < b.px; }
bool dmp(node a, node b) { return a.py < b.py; }
int n, maxn = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i].x, &p[i].y);
    p[i].px = p[i].x + p[i].y;
    p[i].py = p[i].y - p[i].x;
  }
  sort(p + 1, p + n + 1, cmp);
  maxn = p[n].px - p[1].px;
  sort(p + 1, p + n + 1, dmp);
  maxn = max(maxn, p[n].py - p[1].py);
  printf("%d", maxn);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 2e5 + 5;
struct node {
  int x, y;
} p[N];
bool cmp(node a, node b) { return a.x < b.x; }
bool dmp(node a, node b) { return a.y < b.y; }
int n, maxn = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i].x, &p[i].y);
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      maxn = max(maxn, abs(p[i].x - p[j].x) + abs(p[i].y - p[j].y));
  printf("%d", maxn);
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int n;
  cin >> n;
  int mnSum = INT_MAX;
  int mxSum = INT_MIN;
  int mnDiff = INT_MAX;
  int mxDiff = INT_MIN;

  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    mnSum = min(mnSum, x + y);
    mxSum = max(mxSum, x + y);
    mnDiff = min(mnDiff, x - y);
    mxDiff = max(mxDiff, x - y);
  }

  cout << max(abs(mnSum - mxSum), abs(mnDiff - mxDiff));
}

Error: TLE

Fixed submission:

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

int dist(pair<int, int> a, pair<int, int> b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}

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

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

  int ans = -1;

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

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#define ios ios::sync_with_stdio(false)
#define mem(arr) memset(arr, 0, sizeof(arr))
using namespace std;
typedef long long ll;
const ll maxn = 1e7 + 10;
const ll mod = 1e9 + 7;
int x[maxn], y[maxn];
int main() {
  int n;
  ll ans;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    x[i] = a - b;
    y[i] = a + b;
  }
  sort(x + 1, x + n + 1);
  sort(y + 1, y + n + 1);
  ans = max(x[n] - x[1], y[n] - y[1]);
  cout << ans << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#define ios ios::sync_with_stdio(false)
#define mem(arr) memset(arr, 0, sizeof(arr))
using namespace std;
typedef long long ll;
const ll maxn = 1e7 + 10;
const ll mod = 1e9 + 7;

int x[maxn], y[maxn], ans[maxn];
int main() {
  int n, k = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> x[i] >> y[i];
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans[k++] = abs(x[i] - x[j]) + abs(y[i] - y[j]);
    }
  }
  //	cout<<ans[0];
  //	for(int i = 0;i < n; i++)
  //		cout<<ans[i]<<endl;
  sort(ans, ans + k);
  cout << ans[k - 1] << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

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

  for (ll 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], ll n, ll d) {
  ll pk = 0;
  ll idx = 0;

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

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

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

  return idx;
}

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

  ll pk[2 << d];

  for (ll j = 0; j < 1 << (d); j++) {
    ll cmbn[6] = {0};
    for (ll 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 (ll i = 0; i < n; i++) {
    for (ll 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>

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: Time Limit Exceeded

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

typedef long long ll;
typedef int ii;
// typedef vector<ll> vi;

#define INF 1000000007

#define pi 3.141592654

#define T while (t--)
#define for2(i, a, b) for (i = a; i >= b; i--)
#define for3(i, a, b) for (i = a; i <= b; i = i + 2)
#define for1(i, a, b) for (i = a; i <= b; i++)
#define pb push_back
#define mp make_pair

#include <sstream>

#define si set<ll>
#define se multiset<ll>

typedef long double ld;

typedef vector<ll> vi;

#define bb(arr, nn, xx) upper_bound(arr, arr + nn, xx) - arr
#define aa(arra, nna, xxa) lower_bound(arra, arra + nna, xxa) - arra

#define all(v) sort(v.begin(), v.end())

#define all1(v) sort(v.rbegin(), v.rend())

ii main() {

  ios::sync_with_stdio(0);
  cin.tie(0);

  ll n, i;
  cin >> n;
  ll x, y;
  vector<ll> v, v1;

  for1(i, 1, n) {

    cin >> x >> y;

    ll p = x + y;

    ll p1 = y - x;

    v.pb(p);

    v1.pb(p1);
  }

  all(v);

  all(v1);

  ll q = abs(v[0] - v[n - 1]);

  ll q1 = abs(v1[0] - v1[n - 1]);

  cout << max(q, q1) << "\\n";
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef int ii;
// typedef vector<ll> vi;

#define INF 1000000007

#define pi 3.141592654

#define T while (t--)
#define for2(i, a, b) for (i = a; i >= b; i--)
#define for3(i, a, b) for (i = a; i <= b; i = i + 2)
#define for1(i, a, b) for (i = a; i <= b; i++)
#define pb push_back
#define mp make_pair

#include <sstream>

#define si set<ll>
#define se multiset<ll>

typedef long double ld;

typedef vector<ll> vi;

#define bb(arr, nn, xx) upper_bound(arr, arr + nn, xx) - arr
#define aa(arra, nna, xxa) lower_bound(arra, arra + nna, xxa) - arra

#define all(v) sort(v.begin(), v.end())

#define all1(v) sort(v.rbegin(), v.rend())

ii main() {

  ios::sync_with_stdio(0);
  cin.tie(0);

  ll n, i, j;
  cin >> n;
  ll x, y;
  vector<pair<ll, ll>> v;

  for1(i, 1, n) {

    cin >> x >> y;

    pair<ll, ll> p = mp(x, y);

    v.pb(p);
  }

  ll maximum = 0;

  for1(i, 0, n - 1) {

    for1(j, i + 1, n - 1) {
      ll q = abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second);

      maximum = max(maximum, q);
    }
  }

  cout << maximum << "\\n";
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
// #define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define N 200009
int n;
vector<pair<ll, ll>> v;
vector<ll> vx, vy;
ll f1(ll x, ll y) { return x - y; }
ll f2(ll x, ll y) { return x + y; }

int main() {
  cin >> n;
  v.resize(n);
  vx.resize(n);
  vy.resize(n);
  rep(i, n) {
    scanf("%lld%lld", &v[i].first, &v[i].second);
    vx[i] = v[i].first - v[i].second;
    vy[i] = v[i].first + v[i].second;
  }
  ll ans = 0;
  ll vxmax = *max_element(all(vx));
  ll vymax = *max_element(all(vy));
  ll vxmin = *min_element(all(vx));
  ll vymin = *min_element(all(vy));
  reps(i, n) {
    ans = max(ans, vxmax - vxmin);
    ans = max(ans, vymax - vymin);
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
// #define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define N 200009
int n;
vector<pair<ll, ll>> v;
vector<ll> vx, vy;
ll f1(ll x, ll y) { return x - y; }
ll f2(ll x, ll y) { return x + y; }

int main() {
  cin >> n;
  v.resize(n);
  vx.resize(n);
  vy.resize(n);
  rep(i, n) {
    scanf("%lld%lld", &v[i].first, &v[i].second);
    vx[i] = v[i].first - v[i].second;
    vy[i] = v[i].first + v[i].second;
  }
  ll ans = 0;
  reps(i, n) {
    ans = max(ans, *max_element(all(vx)) - *min_element(all(vx)));
    ans = max(ans, *max_element(all(vy)) - *min_element(all(vy)));
  }

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

#include <bits/stdc++.h>

#define nl '\\n'

using namespace std;

typedef long long ll;

void solve() {
  int N;
  cin >> N;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    x[i] = a, y[i] = b;
  }

  int mx1 = -1e9 - 4, mn1 = 1e9 + 4;
  int mx2 = mx1, mn2 = mn1;
  for (int i = 0; i < N; i++) {
    mx1 = max(mx1, x[i] + y[i]);
    mn1 = min(mn1, x[i] + y[i]);
    mx2 = max(mx2, x[i] - y[i]);
    mn2 = min(mn2, x[i] - y[i]);
  }

  cout << max(mx1 - mn1, mx2 - mn2);
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  cout << nl;
  // }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define nl '\\n'

using namespace std;

typedef long long ll;

void solve() {
  int N;
  cin >> N;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    x[i] = a, y[i] = b;
  }

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

  cout << ans;
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  cout << nl;
  // }

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

#include <bits/stdc++.h>

using namespace std;

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

ll mnht(ll pt[1000000][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[1000000][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 = 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>

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 = 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;
  int64_t x, y, z, w;
  int64_t max_z = 0;
  int64_t min_z = 1e10;
  int64_t max_w = -1e10;
  int64_t min_w = 1e10;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    z = x + y;
    w = x - y;
    max_z = max(max_z, z);
    min_z = min(min_z, z);
    max_w = max(max_w, w);
    min_w = min(min_w, w);
  }
  cout << max(max_z - min_z, max_w - min_w) << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> x(N), y(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  int64_t ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ans = max(ans, abs(x.at(i) - x.at(j)) + abs(y.at(i) - y.at(j)));
    }
  }
  cout << ans << endl;
  return 0;
}