#K78067. Block Sorting Challenge
Block Sorting Challenge
Block Sorting Challenge
In this problem, you are given a list of blocks. Each block is described by four attributes: an identifier, a density, a size, and a type. Your task is to sort these blocks based on the following rules:
- Blocks with a higher density should come first.
- If two blocks have the same density, the block with the larger size should come first.
- If two blocks have both the same density and size, their relative order can be arbitrary.
Mathematically, if a block i has density (d_i) and size (s_i), then block i should come before block j if either [ : d_i > d_j \quad\text{or}\quad (d_i = d_j \text{ and } s_i > s_j). ]
The input is provided via standard input (stdin) and the sorted block identifiers must be printed to standard output (stdout) as a space-separated list.
inputFormat
The input begins with an integer (n) (the number of blocks). The following (n) lines each contain four values: an integer identifier, an integer density, an integer size, and a string representing the block type. These values are separated by spaces.
outputFormat
Output the sorted order of block identifiers as a space-separated list (printed to stdout).## sample
4
1 10 5 Engine
2 8 6 Coach
3 15 4 Freight
4 15 7 Tender
4 3 1 2