Problem D
Intervals
A new streaming service, My Stream, has launched and wants to analyze user activity patterns. Each time a user logs on, the service records the hour they started streaming and the hour they finished.
For example, if a user started streaming at 3 a.m. and ended at 2 p.m., this interval would be recorded as starting at time 3 and ending at time 14, for a total duration of 11 hours.
Given $n$ user intervals, each represented as a pair of integers $[a_i, b_i]$ where $0 \le a_i < b_i \le 24$, and an integer $k$, determine how many hours during the day had at least $k$ users streaming simultaneously.
Input
-
The first line contains two integers $n$ and $k$ ($1 \le n \le 1000$, $1 \le k \le n$) — the number of user intervals and the minimum number of users to count.
-
Each of the next $n$ lines contains two integers $a_i$ and $b_i$ ($0 \le a_i < b_i \le 24$), representing the start and end time of the $i$-th user interval.
Output
Print a single integer — the number of hours during which at least $k$ users were streaming.
| Sample Input 1 | Sample Output 1 |
|---|---|
4 2 12 18 1 13 17 20 18 22 |
4 |
| Sample Input 2 | Sample Output 2 |
|---|---|
7 3 8 17 2 5 3 12 11 23 14 19 10 20 9 13 |
10 |
