eolymp
bolt
Try our new interface for solving problems
Problems

Patriotic Painting 1

Patriotic Painting 1

All points of the real line are initially colored yellow, and you want to make it more colorful. $n$ painters are at your service! If you hire $i$-th painter, he will paint all the real points in the segment $[L_i, R_i]$ with blue color (that is, for every real $x$ with $L_i \le x \le R_i$, if $x$ was colored in blue, it will keep being blue, and if it was yellow, it will become blue). You like blue color, and initially, you wanted to hire all $n$ painters, but then you decided to save up some money. If some subset of these painters would give the same result, why hire more and pay more? So, you decided to hire as few painters as possible so that the result of their work would be the same as if you hired all $n$ painters, but there is an issue: you forgot which pair $[L_i, R_i]$ correspondent to which painter. Find the smallest integer $k$ such that if you hire \textbf{any} $k$ distinct painters, the result of their work would be the same as if you hired all $n$ painters. Here we mean that $2$ colorings of the real line are different if there exists a point $x$ which is colored in yellow in one of them and in blue in another. \InputFile The first line contains a single integer $n$ ($1 \le n \le 200000$) --- the number of segments. The $i$-th of the next $n$ lines contains $2$ integers $L, R$ ($1 \le L_i < R_i \le 10^9$). What a pity that you don't remember which of these pairs corresponds to which painter... \OutputFile Output the smallest integer $k$ such that if you hire any $k$ distinct painters, the end result of their work would be the same as if you hired all $n$ painters. It's easy to see that such $k$ always exists and satisfies $1 \le k \le n$. \Note In the first sample, there are two painters, one would paint segment $[1, 42]$ in blue, and the other one would paint segment $[69, 2021]$, together they would paint segments $[1, 42]$ and $[69, 2021]$ in blue. It's easy to see that $k = 1$ wouldn't work: if you chose a painter who would paint points in $[1, 42]$, point $69.5$ would remain yellow. In the second sample, there are three painters, and all of them would paint the same segment $[1, 3]$, so if you hired all of them, only segment $[1, 3]$ would be painted! What a waste of resources. $k = 1$ is sufficient, as no matter what painter you hire, he would paint the same segment $[1, 3]$. In the second sample, there are four painters, one of which would paint segment $[1, 2]$, another $[2, 3]$, another $[3, 4]$, and the last one $[1, 4]$. If you hired all of them, they would paint segment $[1, 4]$ in blue. $k = 1, 2$ are not sufficient: if you hire only painters corresponding to segments $[1, 2]$, $[2, 3]$, only segment $[1, 3]$ would be colored blue in the end, and point $3.5$ would remain yellow. It's easy to see that any subset of three painters would color all points from segment $[1, 4]$ in blue, so the answer is $3$.
Time limit 1 second
Memory limit 256 MiB
Input example #1
2
1 42
69 2021
Output example #1
2
Input example #2
3
1 3
1 3
1 3
Output example #2
1
Input example #3
4
1 2
2 3
3 4
1 4
Output example #3
3
Author Anton Trygub
Source All-Ukrainian Collegiate Programming Contest 2021-2022, II stage