#C9332. Minimum Interval Removal

    ID: 53414 Type: Default 1000ms 256MiB

Minimum Interval Removal

Minimum Interval Removal

You are given n intervals, where each interval is defined by its starting and ending time. Your task is to remove the minimum number of intervals so that the remaining intervals do not overlap with each other.

Note: Two intervals [a, b] and [c, d] are considered non-overlapping if b ≤ c or d ≤ a.

For example, consider the intervals [1,2], [2,3], [3,4], and [1,3]. By removing the interval [1,3], the rest of the intervals become non-overlapping, so the answer is 1.

inputFormat

The input is read from standard input (stdin). The first line contains an integer n, representing the number of intervals. Each of the next n lines contains two integers separated by a space, representing the start and end times of an interval.

outputFormat

Print to standard output (stdout) a single integer representing the minimum number of intervals you need to remove to make the rest non-overlapping.## sample

4
1 2
2 3
3 4
1 3
1