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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define EPS 1e-10
using namespace std;
typedef long long ll;
struct Point {
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  Point operator+(Point p) { return Point(x + p.x, y + p.y); }
  Point operator-(Point p) { return Point(x - p.x, y - p.y); }
  Point operator-() { return Point(-x, -y); }
  Point operator*(double lambda) { return Point(x * lambda, y * lambda); }
  Point operator/(double lambda) { return Point(x / lambda, y / lambda); }
  Point rot(double theta) {
    return Point(cos(theta) * x - sin(theta) * y,
                 sin(theta) * x + cos(theta) * y);
  }
  double norm() { return x * x + y * y; }
  double abs_() { return sqrt(norm()); }
  bool operator==(const Point p) const {
    return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
  }
  bool operator<(const Point p) const {
    if (abs(x - p.x) < EPS)
      return y < p.y;
    return x < p.x;
  }
};
typedef Point Vector;
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double det(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
typedef vector<Point> Polygon;
double diameter(Polygon po) {
  int n = po.size(), minp = 0, maxp = 0;
  for (int i = 1; i < n; i++) {
    if (po[i] < po[minp])
      minp = i;
    if (po[maxp] < po[i])
      maxp = i;
  }
  int i = minp, j = maxp;
  double ans = 0.0;
  while (i != maxp || j != minp) {
    ans = max(ans, (po[i] - po[j]).abs_());
    if (det(po[(i + 1) % n] - po[i], po[(j + 1) % n] - po[j]) < EPS) {
      i = (i + 1) % n;
    } else {
      j = (j + 1) % n;
    }
  }
  return ans;
}
int n;
Polygon g;
int main() {
  scanf("%d", &n);
  g.resize(n);
  for (int i = 0; i < n; i++)
    scanf("%lf%lf", &g[i].x, &g[i].y);
  printf("%.10f\\n", diameter(g));
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define EPS 1e-10
using namespace std;
typedef long long ll;
struct Point {
  double x, y;
  Point(int x = 0, int y = 0) : x(x), y(y) {}
  Point operator+(Point p) { return Point(x + p.x, y + p.y); }
  Point operator-(Point p) { return Point(x - p.x, y - p.y); }
  Point operator-() { return Point(-x, -y); }
  Point operator*(double lambda) { return Point(x * lambda, y * lambda); }
  Point operator/(double lambda) { return Point(x / lambda, y / lambda); }
  Point rot(double theta) {
    return Point(cos(theta) * x - sin(theta) * y,
                 sin(theta) * x + cos(theta) * y);
  }
  double norm() { return x * x + y * y; }
  double abs_() { return sqrt(norm()); }
  bool operator==(const Point p) const {
    return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
  }
  bool operator<(const Point p) const {
    if (abs(x - p.x) < EPS)
      return y < p.y;
    return x < p.x;
  }
};
typedef Point Vector;
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double det(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
typedef vector<Point> Polygon;
double diameter(Polygon po) {
  int n = po.size(), minp = 0, maxp = 0;
  for (int i = 1; i < n; i++) {
    if (po[i] < po[minp])
      minp = i;
    if (po[maxp] < po[i])
      maxp = i;
  }
  int i = minp, j = maxp;
  double ans = 0.0;
  while (i != maxp || j != minp) {
    ans = max(ans, (po[i] - po[j]).abs_());
    if (det(po[(i + 1) % n] - po[i], po[(j + 1) % n] - po[j]) < EPS) {
      i = (i + 1) % n;
    } else {
      j = (j + 1) % n;
    }
  }
  return ans;
}
int n;
Polygon g;
int main() {
  scanf("%d", &n);
  g.resize(n);
  for (int i = 0; i < n; i++)
    scanf("%lf%lf", &g[i].x, &g[i].y);
  printf("%.10f\\n", diameter(g));
  return 0;
}