#C708. Optimal Book Arrangement

    ID: 50911 Type: Default 1000ms 256MiB

Optimal Book Arrangement

Optimal Book Arrangement

You are given a collection of books, each identified by a unique ISBN number and its weight. The task is to arrange these books on a shelf to minimize the total lifting effort. The lifting effort for each book is directly proportional to its weight. To minimize the total effort, you should place the lighter books first. In case two books have the same weight, they should be ordered by their ISBN number in ascending order.

Formally, given a list of books \( (isbn_i, w_i) \) for \( i=1,2,...,n \), you need to sort the books such that the ordering is done primarily by the weight \( w_i \) in ascending order and secondarily by the ISBN number if the weights are equal.

You will read the input from standard input and print the sorted ISBN numbers to standard output as a single space-separated line.

inputFormat

The first line contains a single integer \( n \) representing the number of books. This is followed by \( n \) lines, each containing two values: an ISBN number (a 64-bit integer) and a weight (a floating-point number), separated by a space.

Example:

4
9781234567897 1.2
9789876543210 3.4
9781122334455 2.0
9786677889900 1.2

outputFormat

Output a single line containing the sorted list of ISBN numbers separated by a space.

Example:

9781234567897 9786677889900 9781122334455 9789876543210
## sample
4
9781234567897 1.2
9789876543210 3.4
9781122334455 2.0
9786677889900 1.2
9781234567897 9786677889900 9781122334455 9789876543210