Log inSign up
Problems / B028

The sensor inspection order

200 ptsCases 15Set by dongbinna
Added October 30.

Statement

N sensors that measure the state of the soil are planted in a farm. A grid map is drawn over the farm, so the spot of each sensor is written as two integers, a horizontal coordinate and a vertical coordinate. The base point of the map is in front of the barn. A spot west of the barn has a negative horizontal coordinate, and a spot south of the barn has a negative vertical coordinate.

The inspector goes around the sensors one at a time, moving from west to east. So the sensor with the smaller horizontal coordinate is inspected first. When several sensors have the same horizontal coordinate, the one with the smaller vertical coordinate among them is inspected first.

Given the spots of the N sensors, write a program that prints the spot of each sensor in the order they are inspected.

For example, suppose N=4 sensors are planted in the spots shown in the table below.

Sensor1234
Horizontal coordinate00-11
Vertical coordinate0-100

Looking at the horizontal coordinates, sensor 3 is the smallest at -1 and sensor 4 is the largest at 1. Sensor 1 and sensor 2 both have a horizontal coordinate of 0, so the order between those two is decided by the vertical coordinate. The vertical coordinate of sensor 2 is -1, which is smaller, so sensor 2 is inspected first. The inspection order is therefore the following.

Order1234
Sensor3214
Horizontal coordinate-1001
Vertical coordinate0-100

So in this case the spots (-1, 0), (0, -1), (0, 0), and (1, 0) are printed in that order over four lines.

No two sensors are planted in the same spot. The inspection order therefore comes out as exactly one order.

Input and Output Examples

Example 1

Input

4
0 0
0 -1
-1 0
1 0

Output

-1 0
0 -1
0 0
1 0

Example 2

Input

1
-85572 -65220

Output

-85572 -65220

Example 3

Input

5
-43260 -48523
63588 39993
-46088 77607
-3442 -87816
17118 -62999

Output

-46088 77607
-43260 -48523
-3442 -87816
17118 -62999
63588 39993

Input

  • First, the first line gives the number of sensors N. N is a natural number between 1 and 100,000.

  • Next, over N lines, the spot of each sensor is given one per line. Each line gives the horizontal coordinate and then the vertical coordinate in order, separated by one space. Both coordinates are integers whose absolute value is at most 100,000. Also, the same spot is never given twice.

Output

  • Print the horizontal coordinate and the vertical coordinate of each sensor, separated by one space, one sensor per line, in the order they are inspected.

Requirements

  • Read the input from standard input and write the result to standard output
  • Inspect the sensor with the smaller horizontal coordinate first
  • When the horizontal coordinates are the same, inspect the sensor with the smaller vertical coordinate first
  • Print the two coordinates of one sensor on one line, separated by one space
  • 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.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
1
-85572 -65220
-85572 -65220
5
-43260 -48523
63588 39993
-46088 77607
-3442 -87816
17118 -62999
-46088 77607
-43260 -48523
-3442 -87816
17118 -62999
63588 39993
4
0 0
0 -1
-1 0
1 0
-1 0
0 -1
0 0
1 0

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.

0 chars1 lineMemory 256MB (recorded only)Reference 106ms

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.