Java Programming Consider a set of n intervals I1,...,In, each given as an integer tuple (si,fi) with si
Java Programming
Consider a set of n intervals I1,...,In, each given as an integer tuple (si,fi) with si<fi, such that the ith interval starts at si and ends at fi. We want to determine the maximum number of nonoverlapping intervals. More formally, we want to determine the size of a largest subset S⊆{1,...,n} such that for i, j∈S, with i≠j we have fj≤si or fi≤sj. Note that the intervals [1,2] and [2,3] are not considered to be overlapping.
Input
The first line of input consists of an integer n∈{1,...,105}, the number of intervals. Each of the following n lines consists of two space-separated integers ss and ff, indicating an interval starting at s and ending at f, with 0≤s<f≤109.
requirements:
CPU Time limit: 4 seconds
Memory limit: 1024 MB
Output
Output a single integer, the largest number of nonoverlapping intervals.


Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images









