#C2917. Job Scheduling without Overlaps

    ID: 46286 Type: Default 1000ms 256MiB

Job Scheduling without Overlaps

Job Scheduling without Overlaps

You are given a set of jobs. Each job has a name, a start time, and an end time. Your task is to select the maximum number of jobs that can be scheduled without overlapping. Jobs should be scheduled using a greedy algorithm by sorting them based on their finishing times (and by lexicographical order of the names in case of ties). Specifically, if the start time of a job is greater than or equal to the finish time of the last selected job, then the job can be scheduled.

Mathematically, for jobs with start times ( s_i ) and finish times ( f_i ) for ( i=1,2,...,n ), you need to choose a subset ( S ) such that for each job ( j ) in ( S ), ( s_j \geq f_{previous} ), and ( |S| ) is maximized.

inputFormat

The first line contains an integer ( N ) representing the number of jobs. Each of the following ( N ) lines contains a job description with a job name (a string without spaces), a start time (an integer), and an end time (an integer) separated by spaces.

outputFormat

Output a single line containing the selected job names separated by a single space in the order they are scheduled.## sample

5
Job1 1 3
Job2 2 5
Job3 4 6
Job4 5 8
Job5 7 9
Job1 Job3 Job5