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


// 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)

/*
        ARIJIT SUR
        @duke_knight
        @surcode
    @comeback
        IIT ISM
 */
#include <bits/stdc++.h>
#define SIZE (ll)(1e6)
#define mod (ll)(1e9 + 7)
#define vi vector<ll>
#define INF 0x3f3f3f3f
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define abs(a) ((a) > 0 ? (a) : -(a))
#define sc(a) scanf("%d\\n", &a);
#define all(a) a.begin(), a.end()
#define maxelem(a) *max_element(all(a))
#define minelem(a) *min_element(all(a))
#define pb push_back
#define pi pair<int, int>
#define pqq priority_queue
#define sort(a) sort(all(a))
#define reverse(a) reverse(all(a))
#define input(a)                                                               \\
  {                                                                            \\
    for (int i1 = 0; i1 < a.size(); i1++)                                      \\
      cin >> a[i1];                                                            \\
  }
#define display(a)                                                             \\
  {                                                                            \\
    for (int i1 = 0; i1 < a.size(); i1++)                                      \\
      cout << a[i1] << " ";                                                    \\
    cout << endl;                                                              \\
  }
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long int
#define ull unsigned ll
using namespace std;
#define manhat(a, b) (abs((a[0] - b[0])) + abs((a[1] - b[1])))
void solve() {
  int n;
  cin >> n;
  vector<vi> a(n, vi(2, 0));
  ull ans = 0;
  for (int i = 0; i < n; i++)
    input(a[i]);
  vi plus, minus;
  for (int i = 0; i < n; i++)
    plus.pb(a[i][0] + a[i][1]);
  for (int i = 0; i < n; i++)
    minus.pb(a[i][0] - a[i][1]);
  ll x = maxelem(plus) - minelem(plus), y = maxelem(minus) - minelem(minus);
  cout << max(x, y) << endl;
}
int main() {
  IOS
      // freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
      int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Error: TLE

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)

/*
        ARIJIT SUR
        @duke_knight
        @surcode
    @comeback
        IIT ISM
 */
#include <bits/stdc++.h>
#define SIZE (ll)(1e6)
#define mod (ll)(1e9 + 7)
#define vi vector<int>
#define INF 0x3f3f3f3f
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define abs(a) ((a) > 0 ? (a) : -(a))
#define sc(a) scanf("%d\\n", &a);
#define all(a) a.begin(), a.end()
#define maxelem(a) *max_element(all(a))
#define minelem(a) *min_element(all(a))
#define pb push_back
#define pi pair<int, int>
#define pqq priority_queue
#define sort(a) sort(all(a))
#define reverse(a) reverse(all(a))
#define input(a)                                                               \\
  {                                                                            \\
    for (int i1 = 0; i1 < a.size(); i1++)                                      \\
      cin >> a[i1];                                                            \\
  }
#define display(a)                                                             \\
  {                                                                            \\
    for (int i1 = 0; i1 < a.size(); i1++)                                      \\
      cout << a[i1] << " ";                                                    \\
    cout << endl;                                                              \\
  }
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long int
#define ull unsigned ll
using namespace std;
#define sqr(x) ((x) * (x))
#define manhat(a, b) (abs((a[0] - b[0])) + abs((a[1] - b[1])))
void solve() {
  int n;
  cin >> n;
  vector<vi> a(n, vi(2, 0));
  ull ans = 0;
  for (int i = 0; i < n; i++)
    input(a[i]);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = max(ans, manhat(a[i], a[j]));
    }
  }
  cout << ans;
}
int main() {
  IOS
      // freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
      int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}