Log inSign up
Problems / B029

Setting the viewing order

200 ptsCases 15Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

The floor of an exhibition hall has a grid of lines drawn on it, and N artworks stand on that grid. The position of each artwork is written as two integers, a horizontal coordinate and a vertical coordinate. The origin is the entrance of the hall, so a position to the left of the entrance has a negative horizontal coordinate and a position in front of the entrance has a negative vertical coordinate.

A guide wants to fix the viewing order. The hall is split into rows along the vertical direction, so the guide starts with the artworks that have the smaller vertical coordinate. When several artworks share the same vertical coordinate, the guide starts with the one that has the smaller horizontal coordinate.

Given the positions of the N artworks, write a program that prints the position of each artwork in the order the guide takes them.

For example, suppose N=4 artworks stand at the positions in the following table.

Artwork1234
Horizontal coordinate00-11
Vertical coordinate0-100

Looking at the vertical coordinates, artwork 2 is the smallest with -1, so artwork 2 comes first. The other three artworks all have vertical coordinate 0, so the horizontal coordinate settles their order. That gives artwork 3 with -1, then artwork 1 with 0, then artwork 4 with 1. So the viewing order is the following.

Order1234
Artwork2314
Horizontal coordinate0-101
Vertical coordinate-1000

So in this case the positions (0, -1), (-1, 0), (0, 0) and (1, 0) are printed in that order across four lines. On a printed line the horizontal coordinate comes first and the vertical coordinate comes after it.

No two artworks stand at the same position. The viewing order is therefore settled in exactly one way.

Input and output examples

Example 1

Input

4
0 0
0 -1
-1 0
1 0

Output

0 -1
-1 0
0 0
1 0

Example 2

Input

1
-76106 -25518

Output

-76106 -25518

Example 3

Input

5
-84341 -98243
-81598 -28345
-41076 -63332
-90919 -57927
45391 54278

Output

-84341 -98243
-41076 -63332
-90919 -57927
-81598 -28345
45391 54278

Input

  • The first line gives the number of artworks N. N is a natural number from 1 to 100,000.

  • The next N lines give the position of each artwork, one position per line. Each line gives the horizontal coordinate and then the vertical coordinate, separated by one space. Both coordinates are integers whose absolute value is at most 100,000. No position is given twice.

Output

  • Print the horizontal coordinate and the vertical coordinate of each artwork, one artwork per line, separated by one space, in the order the guide takes them. The very end of the output therefore holds two newline characters. Grading compares the output with the expected value character by character, so leaving out this blank line is marked wrong even when the order is correct.

Requirements

  • Read the input from standard input and write the result to standard output
  • Start with the artwork that has the smaller vertical coordinate
  • When the vertical coordinates are equal, start with the artwork that has the smaller horizontal coordinate
  • On a printed line, write the horizontal coordinate first and the vertical coordinate after it
  • 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
-76106 -25518
-76106 -25518
5
-84341 -98243
-81598 -28345
-41076 -63332
-90919 -57927
45391 54278
-84341 -98243
-41076 -63332
-90919 -57927
-81598 -28345
45391 54278
4
0 0
0 -1
-1 0
1 0
0 -1
-1 0
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 116ms

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.

1bampal2754ms216 charsPythonWindows NT 10.0 / Chrome/156.0.0.0 / 8코어 / 16GB

Log in and you can see the code once you solve this problem.