Writing the elevations in order
Statement
A surveyor walked a mountain trail and recorded the elevations above sea level of N points. An elevation is written as an integer in meters, with a point higher than sea level written as a positive number and a point lower than sea level written as a negative number. The elevation of a point level with the sea is 0.
The record is written in the order the surveyor walked, so high points and low points are mixed together. After finishing the record, the surveyor wants to sort the points again, from the lowest elevation up to the highest.
Given the N recorded elevations, write a program that prints them one per line, in order from the lowest.
For example, suppose the elevations of N=3 points are as in the table below. The elevations of points 1, 2, and 3 are written in the order the surveyor walked.
| Point | 1 | 2 | 3 |
|---|---|---|---|
| Elevation | 287 | -858 | -392 |
The lowest of the three points is point 2, whose elevation is -858. Next comes point 3 at -392, and the highest is point 1 at 287. So the sorted result is the following.
| Order | 1 | 2 | 3 |
|---|---|---|---|
| Point | 2 | 3 | 1 |
| Elevation | -858 | -392 | 287 |
So in this case -858, -392, and 287 are printed one per line in that order.
A point with a negative elevation always comes before a point with a positive one. For example, suppose the elevations of N=2 points are as in the table below.
| Point | 1 | 2 |
|---|---|---|
| Elevation | 150 | -245 |
Here point 2, which is lower than sea level, comes first, so the sorted result is -245 and 150.
| Order | 1 | 2 |
|---|---|---|
| Point | 2 | 1 |
| Elevation | -245 | 150 |
The same elevation is never recorded twice. In the sorted result, an elevation written earlier is therefore always smaller than one written later.
Input and Output Examples
Example 1
Input
3 287 -858 -392
Output
-858 -392 287
Example 2
Input
1 940
Output
940
Example 3
Input
2 150 -245
Output
-245 150
Input
First, the first line gives the number of recorded points N. N is a natural number between 1 and 1,000.
Next, over N lines, the elevation of each point is given one per line, in the order the surveyor walked. Each elevation is an integer whose absolute value is at most 1,000, so it takes a value between -1,000 and 1,000. Also, no elevation is repeated.
Output
Print the elevations one per line, in order from the lowest.
Requirements
- Read the input from standard input and write the result to standard output
- Print the elevations in order from the lowest
- Print one elevation per line
- Grading weighs your output against the expected value down to the last character
- You must write a program that reads from standard input and writes to standard output
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 15 cases to solve this.
Examples
3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.
1 940
940
2 150 -245
-245 150
3 287 -858 -392
-858 -392 287
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 3 public cases. Submitting runs the hidden cases too.
People who solved this problem
Nobody yet. You could be the first.