#C11476. Task Scheduling to Minimize Maximum Lateness

    ID: 40796 Type: Default 1000ms 256MiB

Task Scheduling to Minimize Maximum Lateness

Task Scheduling to Minimize Maximum Lateness

You are given a set of n tasks, each defined by a name, a deadline and a duration. The objective is to schedule the tasks in an order that minimizes the maximum lateness. Formally, if a task i finishes at time C_i and has a deadline d_i, its lateness is defined as \(L_i = \max(0, C_i - d_i)\). The goal is to minimize \(\max_i L_i\) over all tasks. It is known that a greedy strategy, which schedules the tasks in non-decreasing order of their deadlines (Earliest Deadline First), yields an optimal solution.

Your program should read the tasks from standard input and output the sequence of task names (separated by a space) in the order they should be executed.

inputFormat

The first line contains an integer n, the number of tasks. Each of the following n lines contains a task description with three values separated by spaces: a string name, an integer deadline and an integer duration.

For example:

3
A 4 2
B 2 1
C 5 3

outputFormat

Output a single line containing the task names in the order they should be executed, separated by spaces.

For the sample input above, the expected output would be:

B A C
## sample
3
A 4 2
B 2 1
C 5 3
B A C