#C2894. Maximum Non-Overlapping Appointments
Maximum Non-Overlapping Appointments
Maximum Non-Overlapping Appointments
You are given a set of appointments, each with a start time and an end time. Your task is to determine the maximum number of non-overlapping appointments that can be scheduled.
Problem Analysis:
You are provided with an integer n representing the number of appointments. Each of the following n lines contains two integers denoting the start time and the end time of an appointment.
Two appointments are non-overlapping if the start time of an appointment is greater than or equal to the end time of the previous appointment. To solve this problem, a greedy algorithm sorted by the appointment end times can be applied.
The solution is based on the following formula in LaTeX format:
$$\text{If } s_i \geq e_{prev} \text{ then count }++$$
where \( s_i \) is the start time of the current appointment and \( e_{prev} \) is the end time of the most recently selected appointment.
inputFormat
The first line of input contains a single integer n (\(1 \le n \le 10^5\)), which is the number of appointments.
The following n lines each contain two integers representing the start time and end time of an appointment. It is guaranteed that the start time is less than the end time for each appointment.
Example:
3 60 120 130 170 100 240
outputFormat
Output a single integer which is the maximum number of non-overlapping appointments.
Example:
2## sample
3
60 120
130 170
100 240
2
</p>