ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

Bulgarian Contest September 2001

About     Problems     Submit solution     Judge status     Standings
Contest is over

E. Cover

Time limit: 0.5 second
Memory limit: 64 MB
You are given N (0 < N < 100) line segments on a line. Every segment is defined with its endpoints Ai and Bi (Ai ≠ Bi, 1 ≤ i ≤ N). The endpoints are integer coordinates in the interval [−999, 999]. Some of the segments probably intersect. Write a program, which removes minimum number of the given segments, so that none of the left segments have common interior point.


The first line of input contains the integer N. Each of the following N lines, contains two integers (Ai and Bi), separated with one space.


On the first line write the integer P, equal to the number of segments, which are left after your program removes the excess segments. The following P lines should contain the coordinates of the left and the right endpoints of the segments which are left. These coordinates must be separated with one space. Coordinates of the left endpoints must be written in their ascending order. If the problem has more the one solution, write only one of them no matter which.


6 3
1 3
2 5
1 3
3 6
Problem Source: Bulgarian National Olympiad Day #2
To submit the solution for this problem go to the Problem set: 1112. Cover