Problem p02556 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const long long inf = (1ll << 60);
long long n, ans;
struct node {
  long long x, y;
  node(long long u, long long v) { x = u, y = v; }
};
vector<node> c[4], bin;
inline bool cmp1(node x, node y) { return x.x + x.y > y.x + y.y; }
inline bool cmp2(node x, node y) { return -x.x + x.y > -y.x + y.y; }
inline bool cmp3(node x, node y) { return -x.x - x.y > -y.x - y.y; }
inline bool cmp4(node x, node y) { return x.x - x.y > y.x - y.y; }
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
int main() {
  n = read();
  long long u, v;
  u = v = inf;
  for (long long i = 1; i <= n; ++i) {
    long long x = read(), y = read();
    bin.push_back(node(x, y));
    u = min(u, x), v = min(v, y);
  }
  u = -u, v = -v;
  for (long long i = 0; i < n; ++i) {
    bin[i].x += u, bin[i].y += v;
    long long x = (bin[i].x), y = (bin[i].y);
    c[0].push_back(node(x, y));
    c[1].push_back(node(x, y));
    c[2].push_back(node(x, y));
    c[3].push_back(node(x, y));
  }
  sort(c[0].begin(), c[0].end(), cmp1);
  sort(c[1].begin(), c[1].end(), cmp2);
  sort(c[2].begin(), c[2].end(), cmp3);
  sort(c[3].begin(), c[3].end(), cmp4);
  for (long long i = 0; i < n; ++i) {
    long long x = c[0][i].x, y = c[0][i].y;
    for (long long j = 0; j < 4; ++j) {
      u = c[j][0].x, v = c[j][0].y;
      ans = max(ans, abs(x - u) + abs(y - v));
    }
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const long long inf = (1ll << 60);
long long n, ans;
struct node {
  long long x, y;
  node(long long u, long long v) { x = u, y = v; }
};
vector<node> c[4], bin;
inline bool cmp1(node x, node y) { x.x + x.y > y.x + y.y; }
inline bool cmp2(node x, node y) { -x.x + x.y > -y.x + y.y; }
inline bool cmp3(node x, node y) { -x.x - x.y > -y.x - y.y; }
inline bool cmp4(node x, node y) { x.x - x.y > y.x - y.y; }
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
int main() {
  n = read();
  long long u, v;
  u = v = inf;
  for (long long i = 1; i <= n; ++i) {
    long long x = read(), y = read();
    bin.push_back(node(x, y));
    u = min(u, x), v = min(v, y);
  }
  u = -u, v = -v;
  for (long long i = 0; i < n; ++i) {
    long long x = (bin[i].x += u), y = (bin[i].y += v);
    c[0].push_back(node(x, y));
    c[1].push_back(node(x, y));
    c[2].push_back(node(x, y));
    c[3].push_back(node(x, y));
  }
  sort(c[0].begin(), c[0].end(), cmp1);
  sort(c[1].begin(), c[1].end(), cmp2);
  sort(c[2].begin(), c[2].end(), cmp3);
  sort(c[3].begin(), c[3].end(), cmp4);
  for (long long i = 0; i < n; ++i) {
    long long x = c[0][i].x, y = c[0][i].y;
    for (long long j = 0; j < 4; ++j) {
      u = c[j][0].x, v = c[j][0].y;
      ans = max(ans, abs(x - u) + abs(y - v));
    }
  }
  printf("%lld\\n", ans);
  return 0;
}