/* -*- coding: utf-8 -*- * * 2796.cc: No.2796 Small Matryoshka - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ using msi = multiset; using pii = pair; /* global variables */ int irs[MAX_N], ors[MAX_N]; pii ps[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", irs + i, ors + i); for (int i = 0; i < n; i++) ps[i] = {ors[i], irs[i]}; sort(ps, ps + n); msi rs; for (int i = 0; i < n; i++) { auto [ori, iri] = ps[i]; auto sit = rs.upper_bound(iri); if (sit != rs.begin()) rs.erase(--sit); rs.insert(ori); } printf("%d\n", (int)rs.size() - 1); return 0; }