Third argument in sort function

why have we used the bool compare function here in this sort function? what is its use?

You have to sort the activities on increasing order of their end time. So you have made the custom compare function.
By default, sort funtion sorts by considering the first element of the pair. But the end time is at the second element of the pair. This is why custom compare function is required.