루미 알고리즘

#1617골드Divide the Ducks Equally

PO 2025 온라인 예선코딩출제 Joshua Andersson영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

As the benevolent ruler of POland, you want all your citizens to be happy. It is therefore deeply concerning that two children are quarreling. Specifically, they are arguing over 2N kodsport-ducks that are scattered across a plane, and the children disagree about how many ducks each should get.

To resolve the conflict, you need to create a crack in the ground — a straight line that divides the plane into two parts. The crack must be placed so that exactly N ducks end up on each side, ensuring that both children receive the same number of ducks. Each duck is located at an integer coordinate.

Since you prefer simplicity and elegance, your crack will be a straight line of the form y = kx + m, where k and m may be decimal numbers. If such a line exists that divides the ducks equally, output it. Otherwise, print “impossible”.

Input

The first line contains an integer N (1 ≤ N ≤ 10^5), where 2N is the total number of ducks.

The following 2N lines describe the ducks' positions. Each line contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^6), the coordinates of the i-th duck. All ducks have unique positions.

Output

If it is possible to divide the ducks equally, output two real numbers k and m that describe the line y = kx + m. k and m may contain at most 50 characters each. It is guaranteed that the judge will make calculations exactly with k and m. Note that your program might round k and m when they are printed.

The answer will be accepted if the line divides the ducks into two equally sized groups. If multiple solutions exist, you may output any of them. If a duck is exactly on the line, it is considered to be below the line.

If it is impossible to divide the ducks equally, print “impossible”.

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

GroupPointsConstraints
115N = 1
215x_i = 0 for all ducks.
315x_i ≤ 1 for all ducks.
415N = 2
520N ≤ 1000
620No additional constraints.

Explanation of Samples

In each of the following images, all ducks are marked as black dots. The crack used in the sample solution is represented as a red line. Note that there are multiple valid solutions in all cases.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 1: The image represents the first sample.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 2: The image represents the second sample. It is hard to see, but the second point is just below the line.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 3: The image represents the third sample.

예제

예제 1

입력
1
1 1
0 0
출력
-1 1

예제 2

입력
2
0 4
5 4
2 2
1 4
출력
-3 7.00001

예제 3

입력
29
11 21
12 22
13 23
14 23
15 23
16 23
17 22
18 21
18 20
19 19
19 18
19 17
19 16
18 15
18 14
17 13
18 13
19 13
20 13
21 13
22 13
23 13
24 14
25 14
24 13
24 12
23 11
22 10
21 9
20 8
19 7
18 7
17 7
16 7
15 7
14 7
13 7
12 7
11 8
10 9
10 10
10 11
10 12
11 13
12 14
13 14
14 15
15 16
14 17
13 17
12 17
11 17
10 17
9 17
8 17
10 18
11 19
11 20
출력
2.5 -24.9

출처 표기

출처: Programmeringsolympiaden 2025년 온라인 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.