The following implementation assumes that the activities are already sorted according to their finish time
import java . util . * ; import java . lang . * ; import java . io . * ; class ActivitySelection {