intervali
You are given N open intervals on a line (the intervals do not include their endpoints). Your task is to write a program which finds the largest number of intervals that can be chosen so they don't intersect.
InputThe first line of the standard input contains a number N (0<N<=5000), the number of intervals. The next N lines contain two integers li and ri (-10000< li < di <10000) which represent the left and right ends of the interval (1<=i<=N).
OutputTo the standard output in one line write the number of intervals which can be chosen so that they do not intersect.
Input:
Output:
Explanation: The first, third, and fourth intervals don't intersect.
4
-1 1
0 5
2 3
5 9Output:
3Explanation: The first, third, and fourth intervals don't intersect.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.