#C8461. Artifact Sorting
Artifact Sorting
Artifact Sorting
You are given a list of artifacts, where each artifact is represented by a unique identifier and an associated value. Your task is to sort the artifacts in ascending order according to their value while preserving the relative order for artifacts that have the same value. This is a classic stable sorting problem.
For example, if the input is:
5 101 200 102 150 103 200 104 100 105 150
The correct sorted order would be:
104 100 102 150 105 150 101 200 103 200
Note that artifacts with the same value remain in the same order as they were given in the input.
inputFormat
The input is read from standard input. The first line contains an integer n (the number of artifacts). Each of the following n lines contains two space-separated integers: the artifact ID and the artifact value.
outputFormat
Output the sorted list of artifacts to standard output. Each line should contain two space-separated integers, representing the artifact ID and its value. The artifacts must be listed in ascending order according to their value, and for artifacts with the same value, the original input order must be preserved.## sample
5
101 200
102 150
103 200
104 100
105 150
104 100
102 150
105 150
101 200
103 200
</p>