#K83377. Minimize Lateness

    ID: 36184 Type: Default 1000ms 256MiB

Minimize Lateness

Minimize Lateness

You are given a set of tasks. Each task is characterized by a deadline and a duration. Your goal is to determine an order of tasks (by their original 1-indexed positions) to minimize the overall lateness. A common greedy strategy is to sort the tasks based on their deadlines. In case of equal deadlines, the tasks should maintain their original input order.

The problem can be mathematically interpreted as follows: Given tasks \(T_1, T_2, \dots, T_n\) with deadlines \(d_i\) and durations \(t_i\), sort the tasks such that if \(i < j\) then \(d_i \le d_j\) (and if \(d_i = d_j\) then the order remains as in the input). The output should be the permutation of task indices that minimizes the overall lateness when executed sequentially.

inputFormat

The input is read from stdin and has the following format:

 n
 d1 t1
 d2 t2
 ...
 dn tn

Where:

  • n is an integer representing the number of tasks.
  • Each of the next n lines contains two integers: the deadline \(d_i\) and the duration \(t_i\) of the i-th task.

outputFormat

Output a single line on stdout containing n space-separated integers. These integers represent the task indices (1-indexed) in the order that minimizes the overall lateness.

## sample
3
2 1
4 2
3 2
1 3 2

</p>