Activity Selection
Mediumjavapythonccppjavascript
Given N activities with start and finish times, select the maximum number of activities that can be performed by a single person, where a person can only work on one activity at a time. An activity may start exactly when another finishes.
Input Format
The first line contains an integer N. Each of the next N lines contains two integers start and finish (start <= finish).
Output Format
Print the maximum number of non-overlapping activities.
Example 1
Input
5 1 2 3 4 0 6 5 7 8 9
Output
4
Explanation: Choosing activities that finish earliest leaves the most room for later ones.
- 1 <= N <= 100000
- 0 <= start <= finish <= 1000000000