3846.Segments

Time Limit: 1s Memory Limit: 256MB

You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down?

Input Format(From the terminal/stdin)

The first line of the input contains single integer number n (1 \le n \le 1000) - amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers - endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.

Output Format(To the terminal/stdout)

The first line should contain one integer number - the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.

Sample Input 1

Copy
2
0 2
2 5
 \n
 · \n
 · \n

Sample Output 1

Copy
1
2 
 \n
 \n

Sample Input 2

Copy
5
0 3
4 2
4 8
8 10
7 7
 \n
 · \n
 · \n
 · \n
 ·  \n
 · \n

Sample Output 2

Copy
3
7 10 3
 \n
 ·  · \n

Submit

请先 登录

© 2025 FAQs