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

#include <bits/stdc++.h>

using namespace std;

pair<int, int> a[100000];

vector<int> st;

bool ccw(complex<double> a, complex<double> b, complex<double> c) {
  b -= a;
  c -= a;
  c *= conj(b);
  if (c.imag() <= 0) {
    return true;
  }
  return false;
}

void check(int i) {
  while (st.size() >= 2) {
    int s = st[st.size() - 2];
    int e = st[st.size() - 1];
    complex<double> S = complex<double>(a[s].second, a[s].first);
    complex<double> E = complex<double>(a[e].second, a[e].first);
    complex<double> N = complex<double>(a[i].second, a[i].first);
    if (ccw(S, E, N)) {
      break;
    }
    st.pop_back();
  }
  st.push_back(i);
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].second >> a[i].first;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    check(i);
  }
  for (int i = n - 2; i >= 0; i--) {
    check(i);
  }
  cout << st.size() - 1 << endl;
  for (int i = st.size() - 1; i > 0; i--) {
    cout << a[st[i]].second << " " << a[st[i]].first << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

// BINARY_BOY!!
// Bool THINK TWICE CODE ONCE = true;
// Im back basterds
//  MY DICK IS BIG , MY DICK IS VERY VERY BIG
// KEEP CALM AND FUCK PYTHON
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
const int MAXN = 1e5 + 10;
#define salar long double
#define mp make_pair
#define sp setprecision
#define pb push_back
#define pp pop_back
#define oold numeric_limits<long double>::max()
#define _oold numeric_limits<long double>::min()
#define ooint numeric_limits<int>::max()
#define _ooint numeric_limits<int>::min()
#define ooll numeric_limits<long long>::max()
#define _ooll numeric_limits<long long>::min()
#define ct cout
#define vec vector
#define fx fixed
#define cn cin
#define input readInt()
#define print writeInt
#define pc(x) putchar(x)
typedef long long ll;
#define pii pair<int, int>
#define ppi pair<pair<int, int>, int>
#define ppp pair<pair<int, int>, pair<int, int>>
void show(long double a, int x, bool endofline, bool space) {
  ct << fx << sp(x) << a;
  if (endofline)
    ct << endl;
  if (space)
    ct << ' ';
}
int readInt() {
  bool minus = false;
  int result = 0;
  char ch;
  ch = getchar();
  while (true) {
    if (ch == '-')
      break;
    if (ch >= '0' && ch <= '9')
      break;
    ch = getchar();
  }
  if (ch == '-')
    minus = true;
  else
    result = ch - '0';
  while (true) {
    ch = getchar();
    if (ch < '0' || ch > '9')
      break;
    result = result * 10 + (ch - '0');
  }
  if (minus)
    return -result;
  else
    return result;
}
inline void writeInt(long long n) {
  long long N = n, rev, count = 0;
  rev = N;
  if (N == 0) {
    pc('0');
    pc('\\n');
    return;
  }
  while ((rev % 10) == 0) {
    count++;
    rev /= 10;
  } // obtain the count of the number of 0s
  rev = 0;
  while (N != 0) {
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  } // store reverse of N in rev
  while (rev != 0) {
    pc(rev % 10 + '0');
    rev /= 10;
  }
  while (count--)
    pc('0');
}
ll i, x, z, j;
pii pp[MAXN];
vec<ppp> v;
vec<pii> v2;
set<ll> st;
string s;
bool flag2, flag;
void debug() { cout << "DEBUGGING\\n"; }
pii shib(int x1, int y1, int x2, int y2) { return mp(y1 - y2, x1 - x2); }
bool moadelekhat(int x1, int y1, int x2, int y2, int xorg, int yorg) {
  salar h = -1;
  pii mm = shib(x1, y1, x2, y2);
  salar m = mm.first;
  m /= mm.second;
  h = y1 - (m * x1);
  salar yoi = (m * xorg) + h;
  if (yoi < yorg)
    return false;
  return true;
}
bool cmp(ppp p1, ppp p2) {
  return p1.first.first * p2.first.second > p2.first.first * p1.first.second;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ll n;
  cn >> n;
  for (i = 0; i < n; i++) {
    ll a, b;
    a = input;
    b = input;
    pp[i] = (mp(a, b));
  }
  sort(pp, pp + n);
  ll minxi = pp[0].first, minyi = pp[0].second;
  for (i = 1; i < n; i++)
    v.pb(mp(shib(minxi, minyi, pp[i].first, pp[i].second), pp[i]));
  sort(v.begin(), v.end(), cmp);
  int curx = minxi, cury = minyi;
  v2.pb(mp(minxi, minyi));
  v2.pb(v[0].second);
  for (i = 1; i < v.size(); i++) {
    while (!moadelekhat(v2[v2.size() - 2].first, v2[v2.size() - 2].second,
                        v2[v2.size() - 1].first, v2[v2.size() - 1].second,
                        v[i].second.first, v[i].second.second) &&
           i < v.size() - 1 && v2.size() > 2)
      v2.pp();
    v2.pb(mp(v[i].second.first, v[i].second.second));
  }
  for (i = 0; i < v2.size(); i++)
    cout << v2[i].first << ' ' << v2[i].second << '\\n';
}