QOJ.ac

QOJ

実行時間制限: 3 s メモリ制限: 1024 MB 満点: 100

#3190. 聚会

統計

Fictitia 的市民们受够了!这座城市变得越来越大,也越来越无聊。Fictitia 仅由水平和垂直的街道组成。每对相邻平行街道之间的距离始终相同;我们将此距离视为单位距离。难道不该有一些变化吗?

为了争取更多支持并向市政当局表达他们的不满,一群市民商定在城市的一个十字路口聚集进行抗议。问题是:选哪个十字路口?由于它们之间没有太大区别,有人提议选择一个十字路口 $(x^*, y^*)$,使得所有人需要行进的总距离最小。由于每个人都住在十字路口附近,住在 $(x, y)$ 的人所行进的个人距离由 $|x - x^*| + |y - y^*|$ 给出。

然而,这可能会给住得远的人带来问题,因为他们可能难以按时到达。因此,决定该十字路口距离每个人的距离最多为 $d$。在这一限制条件下,你能帮助他们确定一个使所有人行进总距离最小的十字路口吗?

图片由 Radosław Drożdżewski 通过 Wikimedia Commons 提供,采用 cc by-sa 协议

输入格式

输入包含: 一行一个整数 $n$ ($2 \le n \le 100\,000$),表示市民人数; $n$ 行,每行包含两个整数 $x$ 和 $y$ ($0 \le x, y \le 10^9$),表示每位市民住所的坐标; * 一行一个整数 $d$ ($0 \le d \le 2 \cdot 10^9$),表示每位市民需要行进的最大距离。

可能有多个市民住在同一个十字路口。

输出格式

输出一行一个整数:所有市民需要行进的最小总距离。如果不存在一个十字路口使得每个人到该点的距离都在 $d$ 以内,则输出 “impossible”。

样例

输入 1

5
3 1
4 1
5 9
2 6
5 3
10

输出 1

18

输入 2

5
3 1
4 1
5 9
2 6
5 3
5

输出 2

20

输入 3

5
3 1
4 1
5 9
2 6
5 3
4

输出 3

impossible

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.