P10728 [NOISG 2023 Qualification] Swords

Description

YH has $n$ swords. The $i$-th sword has attack power $a_i$ and defense ability $b_i$. For a sword $i$, if there exists a $j(j \not = i)$ such that $a_i \le a_j$ and $b_i \le b_j$, then YH considers this sword useless. Otherwise, he considers it useful. In this problem, it is guaranteed that it is impossible to find two swords $i, j$ such that $a_i = a_j$ and $b_i = b_j$. Please help YH find the number of useful swords among these $n$ swords.

Input Format

The first line contains an integer $n$. The next $n$ lines each contain two integers $a_i, b_i$, representing the attack power and defense ability of the $i$-th sword.

Output Format

Print one integer, the number of useful swords.

Explanation/Hint

|$\text{Subtask}$|Score|Special Property| |:-:|:-:|:-:| |$1$|$11$|$n \le 500$| |$2$|$21$|$a_i, b_i \le 500$| |$3$|$34$|$a_i = i$| |$4$|$25$|For every $1 \le i < j \le n$, $a_i \not = a_j$| |$5$|$9$|None| For all testdata, $1 \le n \le 100000$, $1 \le a_i, b_i \le 10^9$. Translated by ChatGPT 5