#K41467. Maximum Non-Overlapping Book Reading
Maximum Non-Overlapping Book Reading
Maximum Non-Overlapping Book Reading
You are given a list of books, each represented by its start time and end time. A book is read during the interval \([a, b)\), meaning it starts at time \(a\) and finishes before time \(b\). Two books do not overlap if the start time of one is not less than the end time of the other. Your task is to determine the maximum number of books that can be read without overlapping times.
Note: It is assumed that once a book is finished, the next book can be started immediately if its start time is the same as the previous book's end time.
Hint: Consider a greedy strategy where you sort the books by their end times.
inputFormat
The input is given from standard input (stdin) and consists of:
- An integer \(n\) representing the number of books.
- \(n\) subsequent lines, each containing two integers \(a\) and \(b\), indicating the start time and end time of a book.
It is guaranteed that \(0 \leq n \leq 10^5\) and \(0 \leq a < b \leq 10^9\).
outputFormat
Output a single integer to standard output (stdout), which is the maximum number of books that can be read without any overlap.
## sample4
1 2
2 3
3 4
4 5
4