#K82977. Marathon Sequence Arrangement

    ID: 36095 Type: Default 1000ms 256MiB

Marathon Sequence Arrangement

Marathon Sequence Arrangement

In this problem, you are given a list of participants. Each participant has an identifier and a maximum running distance limit. The goal is to arrange the participants in such an order that the total running distance is maximized without any participant running more than their maximum limit. Formally, given participants with limits (d_i), the optimal strategy is to sort them in descending order of (d_i). Note that if two participants have the same running distance limit, they should remain in their original order (i.e., stable sorting).

inputFormat

The input is read from standard input (stdin). The first line contains an integer (n) — the number of participants. Each of the next (n) lines contains two space-separated integers representing the participant's ID and their maximum running distance.

outputFormat

Output to standard output (stdout) a single line containing the participant IDs sorted in the required order (i.e., descending by running distance). The IDs must be separated by a single space.## sample

1
1 5
1

</p>