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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.1415926536
struct Point {
  int x;
  int y;
};
inline double dist(Point a, Point b) {
  return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}
Point point[200005];
Point st[200005];
void getExtremePoint(int n) /// at index 0
{
  int pos = 0;
  for (int i = 1; i < n; i++) {
    if (point[i].y < point[pos].y ||
        (point[i].y == point[pos].y && point[i].x < point[pos].x))
      pos = i;
  }
  swap(point[0], point[pos]);
}
inline int triArea(Point p1, Point p2, Point p3) {
  ll area = 1LL * p1.x * (p2.y - p3.y) + 1LL * p2.x * (p3.y - p1.y) +
            1LL * p3.x * (p1.y - p2.y);
  if (area == 0)
    return area;
  else
    return area / llabs(area);
}
inline bool comp(Point p1, Point p2) {
  int tri = triArea(point[0], p1, p2);
  if (tri < 0)
    return false;
  if (tri == 0 && dist(point[0], p1) > dist(point[0], p2))
    return false;
  return true;
}
bool comp2(Point p1, Point p2) {
  if (p1.x == p2.x)
    return p1.y < p2.y;
  return p1.x < p2.x;
}
int id;
void genConvexPoints(int n) {
  getExtremePoint(n);
  sort(point + 1, point + n, comp);
  id = 0;
  for (int i = 0; i < 3 && i < n; i++)
    st[id++] = point[i];
  for (int i = 3; i < n; i++) {
    while (triArea(st[id - 2], st[id - 1], point[i]) <= 0 && id >= 2)
      id--;
    st[id++] = point[i];
  }
}
int main() {
  int tc, cs = 1, n, d;
  tc = 1;
  while (tc--) {
    set<pair<int, int>> mp;
    scanf("%d", &n);
    int idx = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &point[i].x, &point[i].y);
      mp.insert(make_pair(point[i].x, point[i].y));
      if (mp.size() > idx)
        point[idx++] = point[i];
    }
    n = idx;
    genConvexPoints(n);
    int ans = 0;
    for (int i = 0; i < id; i++) {
      // cout<<i<<" ->> "<<st[i].x<<" "<<st[i].y<<endl;
      for (int j = i + 1; j < id; j++) {
        ans = max(ans, abs(st[i].x - st[j].x) + abs(st[i].y - st[j].y));
      }
    }
    printf("%d\\n", ans);
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.1415926536
struct Point {
  int x;
  int y;
};
inline double dist(Point a, Point b) {
  return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}
Point point[200005];
Point st[200005];
void getExtremePoint(int n) /// at index 0
{
  int pos = 0;
  for (int i = 1; i < n; i++) {
    if (point[i].y < point[pos].y ||
        (point[i].y == point[pos].y && point[i].x < point[pos].x))
      pos = i;
  }
  swap(point[0], point[pos]);
}
inline int triArea(Point p1, Point p2, Point p3) {
  ll area = 1LL * p1.x * (p2.y - p3.y) + 1LL * p2.x * (p3.y - p1.y) +
            1LL * p3.x * (p1.y - p2.y);
  if (area == 0)
    return area;
  else
    return area / llabs(area);
}
inline bool comp(Point p1, Point p2) {
  int tri = triArea(point[0], p1, p2);
  if (tri < 0)
    return false;
  if (tri == 0 && dist(point[0], p1) > dist(point[0], p2))
    return false;
  return true;
}
bool comp2(Point p1, Point p2) {
  if (p1.x == p2.x)
    return p1.y < p2.y;
  return p1.x < p2.x;
}
int id;
void genConvexPoints(int n) {
  getExtremePoint(n);
  sort(point + 1, point + n, comp);
  id = 0;
  for (int i = 0; i < 3 && i < n; i++)
    st[id++] = point[i];
  for (int i = 3; i < n; i++) {
    while (triArea(st[id - 2], st[id - 1], point[i]) < 0)
      id--;
    st[id++] = point[i];
  }
}
int main() {
  int tc, cs = 1, n, d;
  tc = 1;
  while (tc--) {
    set<pair<int, int>> mp;
    scanf("%d", &n);
    int idx = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &point[i].x, &point[i].y);
      mp.insert(make_pair(point[i].x, point[i].y));
      if (mp.size() > idx)
        point[idx++] = point[i];
    }
    n = idx;
    genConvexPoints(n);
    assert(id <= 1000);
    int ans = 0;
    for (int i = 0; i < id; i++) {
      for (int j = i + 1; j < id; j++) {
        ans = max(ans, abs(st[i].x - st[j].x) + abs(st[i].y - st[j].y));
      }
    }
    printf("%d\\n", ans);
  }
}