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

#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
typedef unsigned long long int ulli;
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
using namespace std;
/* TUMSE NAA HO PAAYEGA HAR DO DIN MAI LAGEGA
   LEKIN RUKNE KA NAHI :P */

int main() {
  // your code goes here
  FASTIO
  ll n;
  cin >> n;
  vector<vector<ll>> v(n, vector<ll>(2));
  for (ll i = 0; i < n; i++) {
    cin >> v[i][0] >> v[i][1];
  }
  ll plusmax = INT_MIN, plusmin = INT_MAX, minusmax = INT_MIN,
     minusmin = INT_MAX;
  ll xplusmax, yplusmax, xplusmin, yplusmin, xminusmax, yminusmax, xminusmin,
      yminusmin;
  for (ll i = 0; i < n; i++) {
    if (v[i][0] - v[i][1] > minusmax) {
      minusmax = v[i][0] - v[i][1];
      xminusmax = v[i][0];
      yminusmax = v[i][1];
    }
    if (v[i][0] - v[i][1] < minusmin) {
      minusmin = v[i][0] - v[i][1];
      xminusmin = v[i][0];
      yminusmin = v[i][1];
    }
    if (v[i][0] + v[i][1] > plusmax) {
      plusmax = v[i][0] + v[i][1];
      xplusmax = v[i][0];
      yplusmax = v[i][1];
    }
    if (v[i][0] + v[i][1] < plusmin) {
      plusmin = v[i][0] + v[i][1];
      xplusmin = v[i][0];
      yplusmin = v[i][1];
    }
  }
  ll dist1 = abs(xplusmin - xplusmax) + abs(yplusmin - yplusmax);
  ll dist2 = abs(xminusmin - xminusmax) + abs(yminusmin - yminusmax);
  ll dist = max(dist1, dist2);
  cout << dist << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
typedef unsigned long long int ulli;
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
using namespace std;
/* TUMSE NAA HO PAAYEGA HAR DO DIN MAI LAGEGA
   LEKIN RUKNE KA NAHI :P */

int main() {
  // your code goes here
  FASTIO
  ll n;
  cin >> n;
  ll x, y;
  set<pair<ll, ll>> s;
  for (ll i = 0; i < n; i++) {
    cin >> x >> y;
    s.insert(make_pair(x, y));
  }
  ll dist = INT_MIN;
  for (auto it1 : s) {
    for (auto it2 : s) {
      ll temp = abs(it1.first - it2.first) + abs(it1.second - it2.second);
      dist = max(dist, temp);
    }
  }
  cout << dist << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

struct cdn {
  int x, y;
};

int main() {
  int N, maxRotPls, minRotPls, maxRotMns, minRotMns, ans;
  cin >> N;
  cdn cdns[N];
  for (int i = 0; i < N; i++) {
    cin >> cdns[i].x >> cdns[i].y;
  }

  // 初期化
  maxRotPls = minRotPls = cdns[0].x + cdns[0].y;
  maxRotMns = minRotMns = cdns[0].x - cdns[0].y;
  for (int i = 0; i < N; i++) {
    maxRotPls = max(maxRotPls, cdns[i].x + cdns[i].y);
    minRotPls = min(minRotPls, cdns[i].x + cdns[i].y);
    maxRotMns = max(maxRotMns, cdns[i].x - cdns[i].y);
    minRotMns = min(minRotMns, cdns[i].x - cdns[i].y);
  }
  ans = max(maxRotPls - minRotPls, maxRotMns - minRotMns);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

typedef struct cdn {
  int x, y;
};

int getDistance(cdn cdn1, cdn cdn2) {
  return abs(cdn1.x - cdn2.x) + abs(cdn1.y - cdn2.y);
}

int main() {
  int N, ans;
  cin >> N;
  cdn cdns[N];
  for (int i = 0; i < N; i++) {
    cin >> cdns[i].x >> cdns[i].y;
  }

  ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ans = max(ans, getDistance(cdns[i], cdns[j]));
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double db;

#define MOD 1000000007
#define mini 18446744073709551615
#define ff first
#define ss second
#define pb push_back
#define vii vector<int>
#define pii pair<int, int>
#define vpii vector<pii>

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin>>T;
  while (T--) {
    ll n, ma = -2000000000001, mi = 2000000000001;
    cin >> n;
    ll x, y, mxp = ma, mxm = ma, mip = mi, mim = mi;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      mxp = max(mxp, x + y);
      mxm = max(mxm, x - y);
      mip = min(mip, x + y);
      mim = min(mim, x - y);
    }
    cout << max(mxp - mip, mxm - mim);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double db;

#define MOD 1000000007
#define mini 18446744073709551615
#define ff first
#define ss second
#define pb push_back
#define vii vector<int>
#define pii pair<int, int>
#define vpii vector<pii>

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin>>T;
  while (T--) {
    ll n, ma = 0;
    scanf("%lld", &n);
    ll x[n], y[n];
    for (int i = 0; i < n; i++) {
      scanf("%lld %lld", &x[i], &y[i]);
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        ma = max(abs(x[i] - x[j]) + abs(y[i] - y[j]), ma);
      }
    }
    cout << ma;
  }
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

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

const int mod = 1e9;
int main() {
  int N;
  scanf("%d", &N);

  int Max1 = mod * -1, Min1 = mod;
  int Max0 = mod * -1, Min0 = mod;
  for (int i = 1; i <= N; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);

    Max1 = max(Max1, x + y);
    Min1 = min(Min1, x + y);
    Max0 = max(Max0, x - y);
    Min0 = min(Min0, x - y);
  }
  int ans = max((Max1 - Min1), (Max0 - Min0));
  return printf("%d", ans), 0;
}

Error: 1

Fixed submission:

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

const int mod = 1e9;
int main() {
  int N;
  scanf("%d", &N);

  int Max1 = mod * -1, Min1 = mod;
  int Max0 = mod * -1, Min0 = mod;
  for (int i = 1; i <= N; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);

    Max1 = max(Max1, x + y);
    Min1 = min(Min1, x + y);
    Max0 = max(Max0, x - y);
    Min0 = min(Min0, x - y);
  }
  int ans = max((Max1 - Min1), (Max0 - Min0));
  return printf("%d", ans);
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define MOD 1000000007
#define PI (6.28318530718 / 2.0)
#define ft first
#define sec second
#define ll long long
#define pb push_back
using namespace std;
int n;
int a[200005], b[200005];
int main() {
  cin >> n;
  for (int i = 0, x, y; i < n; i++) {
    cin >> x >> y;
    a[i] = (x + y);
    b[i] = (x - y);
  }
  sort(a, a + n);
  sort(b, b + n);
  cout << max(a[n - 1] - a[0], b[n - 1] - b[0]);
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007
#define PI (6.28318530718 / 2.0)
#define ft first
#define sec second
#define ll long long
#define pb push_back
using namespace std;
int n, a[200005];
pair<int, int> p[200005];
ll dist(int a, int b) {
  return abs(p[a].ft - p[b].ft) + abs(p[a].sec - p[b].sec);
}
int cmp(int a, int b) { return p[a].sec < p[b].sec; }
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> p[i].ft >> p[i].sec, a[i] = i;
  sort(a, a + n, cmp);
  sort(p, p + n);
  ll ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    // if(dist(a[i],n)!=dist(a[n-1],n)) break;
    int j = 0;
    while (p[a[j]].sec == p[0].sec)
      ans = max(ans, dist(i, a[j])), j++;
    j = n - 1;
    while (p[a[j]].sec == p[n - 1].sec)
      ans = max(ans, dist(i, a[j])), j--;
    ans = max({ans, dist(i, 0), dist(i, n - 1)});
  }
  cout << ans;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

ll mnht(ll pt[200005][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 (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;
  cin >> n;
  int 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;
  cin >> n;
  int 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>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) {
  if (u < z) {
    u = z;
    return true;
  } else
    return false;
}
template <typename T> bool chmin(T &u, const T z) {
  if (u > z) {
    u = z;
    return true;
  } else
    return false;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) {
  if (u < z) {
    u = z;
    return true;
  } else
    return false;
}
template <typename T> bool chmin(T &u, const T z) {
  if (u > z) {
    u = z;
    return true;
  } else
    return false;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  int n;
  cin >> n;
  vector<pair<ll, ll>> a, b;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    a.emplace_back(x, y);
    b.emplace_back(y, x);
  }
  sort(a.rbegin(), a.rend());
  ll ans = 0;
  rep(i, min(n, 5000)) {
    for (int j = i + 1; j < n; j++) {
      ll x = abs(a[i].first - a[j].first);
      ll y = abs(a[i].second - a[j].second);
      ans = max(ans, x + y);
    }
  }
  sort(b.rbegin(), b.rend());
  rep(i, min(n, 5000)) {
    for (int j = i + 1; j < n; j++) {
      ll x = abs(b[i].first - b[j].first);
      ll y = abs(b[i].second - b[j].second);
      ans = max(ans, x + y);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#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 < (n); ++i)

const int maxn = 200001;
const int dem = 2;
const double INF = (1e200);
struct Point {
  double x[dem];
} p[maxn];

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

double 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;
  rep(i, n) { rep(j, dem) cin >> p[i].x[j]; }
  double ans = solve();
  cout << (int)ans << endl;
  return 0;
}


Error: 0

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

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];

double 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;
  rep(i, n) { rep(j, dem) cin >> p[i].x[j]; }
  double ans = solve();
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

/*Author : Yuvraj Singh
 * Patience is Power
 *
 * */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const long long mod = 1e9 + 7;
#define ar array
void solve() {
  ll n;
  cin >> n;
  ll dp[] = {-mod, mod, -mod, mod};
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    dp[0] = max(dp[0], x + y);
    dp[1] = min(dp[1], x + y);
    dp[2] = max(dp[2], x - y);
    dp[3] = min(dp[3], x - y);
  }
  ll mx = dp[0] - dp[1];
  ll mi = dp[2] - dp[3];
  ll ans = max(mx, mi);
  cout << ans << "\\n";
}

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

  // int t; cin>>t;
  // while(t--)
  solve();

  return 0;
}


Error: TLE

Fixed submission:

/*Author : Yuvraj Singh
 * Patience is Power
 *
 * */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const long long mod = 1e9 + 7;
void solve() {
  ll n;
  cin >> n;
  ll dp[n];
  dp[0] = -(1e9 + 7);
  dp[1] = (1e9 + 7);
  dp[2] = -(1e9 + 7);
  dp[3] = (1e9 + 7);

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

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

  // int t; cin>>t;
  // while(t--)
  solve();

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


// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define int long long
int mod = 1e9 + 7;
int po(int x, int y, int m) {
  if (y == 0)
    return 1;
  int t = po(x, y / 2, m) % m;
  t = (t * t) % m;
  if (y & 1)
    return (t * x) % m;
  return t % m;
}

signed main() {

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);

  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].first >> v[i].second;
  }
  int ans = INT_MIN;
  int mi1 = INT_MAX;
  int mi2 = INT_MAX;
  int ma2 = INT_MIN;
  int ma1 = INT_MIN;
  for (int i = 0; i < n; ++i) {
    mi1 = min(mi1, v[i].first - v[i].second);
    mi2 = min(mi2, v[i].first + v[i].second);
    ma1 = max(ma1, v[i].first - v[i].second);
    ma2 = max(ma2, v[i].first + v[i].second);
    ans = max({ans, ma2 - mi2, ma1 - mi1});
  }
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:


// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define int long long
int mod = 1e9 + 7;
int po(int x, int y, int m) {
  if (y == 0)
    return 1;
  int t = po(x, y / 2, m) % m;
  t = (t * t) % m;
  if (y & 1)
    return (t * x) % m;
  return t % m;
}

bool cmp2(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second != b.second)
    return a.second < b.second;
  return a.first <= b.first;
}
signed main() {

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);

  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  int dis =
      abs(v[0].first - v[n - 1].first) + abs(v[0].second - v[n - 1].second);
  sort(v.begin(), v.end(), cmp2);
  dis = max(dis, abs(v[0].first - v[n - 1].first) +
                     abs(v[0].second - v[n - 1].second));
  cout << dis << endl;

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

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
int d1[maxn], d2[maxn], n;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    d1[i] = x + y;
    d2[i] = x - y;
  }
  sort(d1, d1 + n);
  sort(d2, d2 + n);
  cout << max(d1[n - 1] - d1[0], d2[n - 1] - d2[0]) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
int x[maxn], y[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> x[i] >> y[i];
  int maxx = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      maxx = max(abs(x[i] - x[j]) + abs(y[i] - y[j]), maxx);
    }
  }
  cout << maxx << 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<vector<int>> data(N, vector<int>(2));

  for (int i = 0; i < N; i++) {
    cin >> data.at(i).at(0) >> data.at(i).at(1);
  }

  int a_max = data.at(0).at(0) + data.at(0).at(1);
  int a_min = data.at(0).at(0) + data.at(0).at(1);
  for (int i = 1; i < N; i++) {
    int temp = data.at(i).at(0) + data.at(i).at(1);
    a_max = max(a_max, temp);
    a_min = min(a_min, temp);
  }

  int b_max = data.at(0).at(0) - data.at(0).at(1);
  int b_min = data.at(0).at(0) - data.at(0).at(1);
  for (int i = 1; i < N; i++) {
    int temp = data.at(i).at(0) - data.at(i).at(1);
    b_max = max(b_max, temp);
    b_min = min(b_min, temp);
  }

  cout << max(a_max - a_min, b_max - b_min) << endl;
}


Error: TLE

Fixed submission:

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

int zettaiti(int x, int y) {
  if (x > y) {
    return x - y;
  } else {
    return y - x;
  }
}

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

  vector<vector<int>> data(N, vector<int>(2));

  for (int i = 0; i < N; i++) {
    cin >> data.at(i).at(0) >> data.at(i).at(1);
  }

  int answer = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N; j++) {
      int temp = zettaiti(data.at(i).at(0), data.at(j).at(0)) +
                 zettaiti(data.at(i).at(1), data.at(j).at(1));
      if (temp > answer) {
        answer = temp;
      }
    }
  }

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

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

#define rep(ver, n) rep2(ver, 0, n)
#define rep2(ver, m, n) for (int ver = m; ver < (n); ver++)
#define loop while (true)
#define dup(x, y) (((x) + (y)-1) / (y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr << #x << ": " << x << "\\n"
#define debug2(x, y)                                                           \\
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\\n"
#define debug3(x, y, z)                                                        \\
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z        \\
            << ": " << z << "\\n"

typedef long long ll;
typedef pair<int, int> P;

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

ll n, x[300000] = {}, y[300000] = {}, sum1[300000] = {}, sum2[300000] = {};

int main() {
  scanf("%d", &n);
  rep(i, n) {
    int tx, ty;
    scanf("%d %d", &tx, &ty);
    x[i] = tx;
    y[i] = ty;
    sum1[i] = tx + ty;
    sum2[i] = tx - ty;
  }

  sort(sum1, sum1 + n);
  sort(sum2, sum2 + n);
  cout << max(abs(sum1[n - 1] - sum1[0]), abs(sum2[n - 1] - sum2[0]));

  return 0;
}


Error: WA

Fixed submission:

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

#define rep(ver, n) rep2(ver, 0, n)
#define rep2(ver, m, n) for (int ver = m; ver < (n); ver++)
#define loop while (true)
#define dup(x, y) (((x) + (y)-1) / (y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr << #x << ": " << x << "\\n"
#define debug2(x, y)                                                           \\
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\\n"
#define debug3(x, y, z)                                                        \\
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z        \\
            << ": " << z << "\\n"

typedef long long ll;
typedef pair<int, int> P;

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

ll n, x[30000] = {}, y[300000] = {}, sum1[300000] = {}, sum2[300000] = {};

int main() {
  scanf("%d", &n);
  rep(i, n) {
    int tx, ty;
    scanf("%d %d", &tx, &ty);
    x[i] = tx;
    y[i] = ty;
    sum1[i] = tx + ty;
    sum2[i] = tx - ty;
  }

  sort(sum1, sum1 + n);
  sort(sum2, sum2 + n);
  cout << max(abs(sum1[n - 1] - sum1[0]), abs(sum2[n - 1] - sum2[0]));

  return 0;
}