Lining up the street lamp positions
Statement
N street lamps stand along a straight road. One point on the road is taken as the base point, and a distance east of the base point is written as a positive number while a distance west of it is written as a negative number. The position of a lamp standing at the base point is 0.
The inspector received a list of the lamps, but the order on the list differs from the order the lamps stand in, which makes it hard to walk once from the west end to the east end and inspect them. The inspector therefore wants to write the list again, from the smallest position to the largest.
Given the positions of the N street lamps, write a program that prints them one per line, in order from the smallest.
For example, suppose the positions of N=5 street lamps are as in the table below.
| Lamp | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Position | -1000000 | 1000000 | 0 | -1 | 1 |
The lamp farthest west is lamp 1, whose position is -1000000, and the lamp farthest east is lamp 2, whose position is 1000000. Lamp 3, which stands at the base point, is east of lamp 4 and west of lamp 5. So the list written again is the following.
| Order | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Lamp | 1 | 4 | 3 | 5 | 2 |
| Position | -1000000 | -1 | 0 | 1 | 1000000 |
So in this case -1000000, -1, 0, 1, and 1000000 are printed one per line in that order.
There can be up to 1,000,000 street lamps. It is therefore better to read the whole input at once, sort it a single time, and gather the result and write it all out at the end.
Input and Output Examples
Example 1
Input
5 -1000000 1000000 0 -1 1
Output
-1000000 -1 0 1 1000000
Example 2
Input
1 -593750
Output
-593750
Example 3
Input
2 225535 322114
Output
225535 322114
Input
First, the first line gives the number of street lamps N. N is a natural number between 1 and 1,000,000.
Next, over N lines, the position of each lamp is given one per line, in the order written on the list. Each position is an integer whose absolute value is at most 1,000,000, so it takes a value between -1,000,000 and 1,000,000. Also, no position is repeated.
Output
Print the positions of the lamps one per line, in order from the smallest.
Requirements
- Read the input from standard input and write the result to standard output
- Print the positions in order from the smallest
- Print one position per line
- Up to 1,000,000 street lamps can come in, so writing them out one line at a time can go over the time limit
- 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 -593750
-593750
2 225535 322114
225535 322114
5 -1000000 1000000 0 -1 1
-1000000 -1 0 1 1000000
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
The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.
Log in and you can see the code once you solve this problem.