포럼
문제 ICPC00167

G. Gathering

설명

The citizens of Fictitia have had enough! The city keeps getting bigger and bigger, and all the more boring. Fictitia consists of horizontal and vertical streets only. The distance between each pair of neighboring parallel streets is always the same; we take this as the unit distance. Surely some variation could not hurt?

In order to draw more support and make their unhappiness known to the municipality, a group of citizens has agreed to gather at an intersection of the city to protest. The question is: which intersection? Since there is not much difference between them, the idea was raised to select an intersection \((x^*,y^*)\) that minimizes the total distance everyone has to travel. Since everyone lives close to an intersection, the individual distance travelled by someone who lives at \((x,y)\) is given by \(|x-x^*|+|y-y^*|\).

However, this could present a problem for the people who live far away, since they might have trouble getting there in time. Therefore it was decided that the intersection should be at most a certain distance \(d\) away from everyone. Given that restriction, can you help them identify an intersection that minimizes the total distance everyone has to travel?

제약
입력 형식

The input consists of:
- one line with one integer \(n\) (\(2 \leq n \leq 100\,000\)), the number of citizens;
- \(n\) lines each with two integers \(x\) and \(y\) (\(0 \leq x,y \leq 10^9\)), the coordinates of each citizen's house;
- one line with one integer \(d\) (\(0 \leq d \leq 2 \cdot 10^9\)), the maximum distance that each citizen should have to travel.

It is possible for multiple citizens to live at the same intersection.

출력 형식

Output one line with a single integer: the smallest possible total distance that all citizens need to travel. If there is no intersection that everyone lives within a distance \(d\) of, output "impossible" instead.

예제 1
입력
5
3 1
4 1
5 9
2 6
5 3
10
출력
18
예제 2
입력
5
3 1
4 1
5 9
2 6
5 3
5
출력
20
예제 3
입력
5
3 1
4 1
5 9
2 6
5 3
4
출력
impossible
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NWERC 2014

평가 및 의견

G. Gathering

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

G. Gathering

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8