Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

2/20/24, 9:35 PM Problem - 1651D - Codeforces

|
stdfloat | Logout

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST

Educational Codeforces Round


D. Nearest Excluded Points 124 (Rated for Div. 2)

time limit per test: 4 seconds Finished


memory limit per test: 256 megabytes Practice
input: standard input
output: standard output

You are given n distinct points on a plane. The coordinates of the i -th point are (x i , yi ).
→ Virtual participation 
For each point i , find the nearest (in terms of Manhattan distance) point with integer
coordinates that is not among the given n points. If there are multiple such points — you can
choose any of them. → Clone Contest to Mashup 

The Manhattan distance between two points (x 1 , y1 ) and (x 2 , y2 ) is |x 1 − x 2 | + |y1 − y2 | .


→ Submit?
Input
The first line of the input contains one integer n (1
5
≤ n ≤ 2 ⋅ 10 ) — the number of points in Language: GNU G++20 11.2.0 (64 bit, w
the set.
Choose
Choose File No file chosen
file:
The next n lines describe points. The i -th of them contains two integers x i and yi (
1 ≤ x i , yi ≤ 2 ⋅ 10
5
) — coordinates of the i -th point. Submit

It is guaranteed that all points in the input are distinct.


→ Contest materials
Output
Print n lines. In the i -th line, print the point with integer coordinates that is not among the
Announcement
given n points and is the nearest (in terms of Manhattan distance) to the i -th point from the
input. Tutorial

Output coordinates should be in range [−10


6 6
; 10 ] . It can be shown that any optimal answer
meets these constraints.

If there are several answers, you can print any of them.

Examples
input Copy

6
2 2
1 2
2 1
3 2
2 3
5 5

output Copy

1 1
1 1
2 0
3 1
2 4
5 4

input Copy

8
4 4
2 4
2 2
2 3

https://codeforces.com/problemset/problem/1651/D 1/2
2/20/24, 9:35 PM Problem - 1651D - Codeforces
1 4
4 2
1 3
3 3

output Copy

4 3
2 5
2 1
2 5
1 5
4 1
1 2
3 2

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Feb/20/2024 21:18:17UTC+5 (f1).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

https://codeforces.com/problemset/problem/1651/D 2/2

You might also like