eolymp
bolt
Try our new interface for solving problems
Problems

Segments

Segments

Segments are given on a line. What is the maximum number of segments that can be selected so that no two of them intersect? The segments are considered open. \InputFile The first line contains the number of segments $n~(1 \le n \le 10^5)$. The next $n$ lines describe the segments: the $i$-th line contains two integers $l_i$ and $r_i~(1 \le l_i < r_i \le 10^9)$ --- the coordinates of the starting and ending points of the segment. \OutputFile Print the maximum number of non-intersecting segments.
Time limit 1 second
Memory limit 128 MiB
Input example #1
5
1 4
3 8
7 8
2 5
4 6
Output example #1
3
Input example #2
4
1 3
2 6
1 8
2 5
Output example #2
1
Author Ivan Kazmenko