Objective
A greedy algorithm picks the locally best option at each step. To fit the maximum number of activities without overlaps, the right strategy is to sort by end time and always keep the first one that starts after the previous one ends.
Instructions
- The first line has the number
nof activities; thennlinesstart end. An activity may start exactly when another ends. - Show
Activities: nwith the maximum number of activities that can be done without overlapping.
5
1 4
3 5
0 6
5 7
8 9
Activities: 3
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise