#K65192. Minimum Points Covering Intervals
Minimum Points Covering Intervals
Minimum Points Covering Intervals
Given n intervals of the form \([l_i, r_i]\), your task is to compute the minimum number of points such that every interval contains at least one selected point. The common greedy approach is to sort the intervals by their right endpoints and then iteratively select the rightmost endpoint of the current interval that is not yet covered.
In mathematical terms, for each interval \([l_i, r_i]\), you need to find a set of points \(P = {p_1, p_2, \ldots, p_k}\) such that for every \(i\), there exists a point \(p_j\) satisfying \(l_i \leq p_j \leq r_i\). Your goal is to minimize \(k\), the number of points chosen.
inputFormat
The first line contains an integer n representing the number of intervals.
Each of the next n lines contains two space-separated integers l and r denoting the endpoints of an interval \([l, r]\).
outputFormat
Output a single integer: the minimum number of points required to cover all the given intervals.
## sample3
1 3
2 5
3 6
1
</p>