#K71137. Maximum Non-Overlapping Projects
Maximum Non-Overlapping Projects
Maximum Non-Overlapping Projects
You are given a list of projects, each with a start time and an end time. Your task is to determine the maximum number of non-overlapping projects that can be scheduled.
Two projects are considered non-overlapping if the start time of one project is greater than or equal to the end time of the previously selected project. Formally, if we denote each project by the interval \( [s_i, e_i] \), and the projects are sorted by their end times in increasing order, then a project \( i \) can be chosen if \( s_i \geq e_{last} \), where \( e_{last} \) is the end time of the last selected project.
The input will be provided via standard input and the output should be printed to standard output. Use a greedy algorithm to achieve an optimal solution.
inputFormat
The first line contains an integer ( N ) representing the number of projects. Each of the following ( N ) lines contains two space-separated integers representing the start time and end time of a project.
outputFormat
Output a single integer representing the maximum number of non-overlapping projects.## sample
3
1 3
2 4
3 5
2