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

#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 100005;
const int MAXM = 50005;
const double EPS = 1e-8;
const int MOD = 1e9 + 7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync                                                              \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mst(X, Y) memset(X, Y, sizeof(X))
#define rep(i, a, n) for (int i = (a); i <= (n); i++)
#define per(i, a, n) for (int i = (a); i >= (n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

void solve() {
  int n;
  cin >> n;
  vector<vector<ll>> v(5);
  rep(i, 1, n) {
    ll x, y;
    cin >> x >> y;
    v[1].push_back(x + y);
    v[2].push_back(x - y);
    v[3].push_back(-x + y);
    v[4].push_back(-x - y);
  }
  rep(i, 1, 4) sort(v[i].begin(), v[i].end());
  ll ans = 0;
  rep(i, 1, 4) ans = max(ans, v[i][n - 1] - v[i][0]);
  cout << ans << endl;
}

int main() {
  closeSync;
#ifdef DEBUG
  // freopen("C:/Users/86159/Desktop/a2.in.txt", "r", stdin);
  // freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
  // clock_t c1 = clock();

  solve();

  // cerr << "Time:" << clock() - c1 << "ms" <<endl;
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2005;
const int MAXM = 50005;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync                                                              \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mst(X, Y) memset(X, Y, sizeof(X))
#define rep(i, a, n) for (int i = (a); i <= (n); i++)
#define per(i, a, n) for (int i = (a); i >= (n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <typename T, typename T1> inline T qpower(T x, T p, T1 mod) {
  T re = 1;
  x %= mod;
  while (p) {
    if (p & 1)
      re = (re * x) % mod;
    x = (x * x) % mod;
    p >>= 1;
  }
  return re;
}

inline int dis(pii &a, pii &b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}
vector<pii> v;
void solve() {
  int n;
  cin >> n;
  rep(i, 1, n) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }
  int ans = 0;
  rep(i, 0, n - 2) rep(j, i + 1, n - 1) ans = max(ans, dis(v[i], v[j]));
  cout << ans << endl;
}

int main() {
  closeSync;
#ifdef DEBUG
  // freopen("C:/Users/86159/Desktop/a2.in.txt", "r", stdin);
  // freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
  // clock_t c1 = clock();

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

  // cerr << "Time:" << clock() - c1 << "ms" <<endl;
  return 0;
}