Problem p02556 (C++) — buggy submission, verdict: Runtime Error

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

#define sync                                                                   \\
  {                                                                            \\
    ios_base ::sync_with_stdio(false);                                         \\
    cin.tie(NULL);                                                             \\
    cout.tie(NULL);                                                            \\
  }
#define ll long long int
#define mod 1000000007

int n;

bool c(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.first + a.second) < (b.first + b.second);
}

bool c1(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.first - a.second) < (b.first - b.second);
}

void solve() {
  cin >> n;
  //    ll maxm = 0;
  //    ll minm = 1e10;
  //    pair<ll,ll> ans1,ans2;
  //
  vector<pair<ll, ll>> points(n);
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;

    points[i].first = x;

    points[i].second = y;
  }

  vector<pair<ll, ll>> pts = points;

  sort(pts.begin(), pts.end(), c1);

  sort(points.begin(), points.end(), c);

  cout << max((points[n - 1].first + points[n - 1].second) -
                  (points[0].first + points[0].second),
              ((pts[n - 1].first - pts[n - 1].second) -
               (pts[0].first - pts[0].second)));
}

int main() {
  sync;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}


Error: -11

Fixed submission:

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

#define sync                                                                   \\
  {                                                                            \\
    ios_base ::sync_with_stdio(false);                                         \\
    cin.tie(NULL);                                                             \\
    cout.tie(NULL);                                                            \\
  }
#define ll long long int
#define mod 1000000007

int n;

void solve() {
  cin >> n;
  ll maxm = 0;
  ll minm = 1e10;
  pair<ll, ll> ans1, ans2;

  vector<pair<ll, ll>> points;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;

    points[i].first = x;

    points[i].second = y;

    if (abs(x + y) < minm) {
      minm = abs(x + y);
      ans1.first = x;
      ans1.second = y;
    }
    if (abs(x + y) > maxm) {
      maxm = abs(x + y);
      ans2.first = x;
      ans2.second = y;
    }
  }

  if (ans1 != ans2) {
    cout << abs(minm - maxm);
    return;
  }

  ll tmin = 1e10;
  ll tmax = 0;

  for (int i = 0; i < n; i++) {
    if (abs(points[i].first + points[i].second) < tmin and
        !(points[i].first == ans1.first and points[i].second == ans1.second)) {
      tmin = abs(points[i].first + points[i].second);
    }
    if (abs(points[i].first + points[i].second) > tmax and
        !(points[i].first == ans2.first and points[i].second == ans2.second)) {
      tmax = abs(points[i].first + points[i].second);
    }
  }

  cout << max(abs(tmin - maxm), abs(minm - tmax));
}

int main() {
  sync;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}