#K92427. Maximum Non-Overlapping Activities
Maximum Non-Overlapping Activities
Maximum Non-Overlapping Activities
You are given a list of activities where each activity is represented by its start time and end time. Your task is to determine the maximum number of activities that can be attended assuming that only one activity can be attended at a time. In other words, you need to select a subset of activities such that no two activities overlap.
Note: If an activity finishes at time t, another activity that starts at time t can be attended.
The problem can be solved using a greedy algorithm by first sorting the activities based on their end times. Then, iteratively, the next activity which starts after or exactly when the last selected activity ended is chosen.
The answer should be output to stdout.
inputFormat
The first line of input contains a single integer n representing the number of activities.
Each of the following n lines contains two space-separated integers start and end which denote the start time and finish time of an activity respectively.
Input is given via stdin.
outputFormat
Output a single integer which is the maximum number of non-overlapping activities that can be attended.
Output should be printed to stdout.
## sample5
1 4
3 5
0 6
5 7
8 9
3