QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 32 MB Points totaux : 100

#476. 仓库

Statistiques

New Byte City 的街道构成了一个矩形网格——东西走向的街道简称为街道(streets),南北走向的街道简称为大道(avenues)。为了避免混淆,我们分别称它们为 h-streets 和 v-streets。v-streets 从西向东编号为 $1$ 到 $500\,000\,000$。同样地,h-streets 从南向北编号为 $1$ 到 $500\,000\,000$。每一条 v-street 都与每一条 h-street 相交,反之亦然。相邻两条 v-street 之间以及相邻两条 h-street 之间的距离均为一公里。

城里有 $k$ 家商店,每一家都位于一个十字路口。商人 Byteasar 为这 $k$ 家商店中的每一家供货,此外,他每天还会多次回到其中一些商店补充新鲜货物。最近,他决定建造一个仓库,以便从中运送货物。出于显而易见的原因,仓库应该建在一个十字路口。装载货物的卡车每次行程只能供应一家商店——它从仓库出发,将货物送到商店,然后返回仓库。卡车总是选择从仓库到商店的最短路径,以及返回时的最短路径(可能是同一条路径)。点 $(x_i,y_i)$ 和 $(x_j,y_j)$ 之间的距离等于 $\max\{|x_i-x_j|,|y_i-y_j|\}$。

任务

编写一个程序,完成以下工作:

  • 从标准输入读取商店的位置以及它们每天的配送次数;
  • 确定仓库的位置,使得卡车每日行程的总距离最小;
  • 将结果写入标准输出。

输入格式

标准输入的第一行包含一个整数 $n$ ($1 \le n \le 100\,000$),表示 New Byte City 中商店的数量。

接下来的 $n$ 行包含商店的描述。第 $(i+1)$ 行包含三个整数 $x_i$、$y_i$ 和 $t_i$ ($1 \le x_i,y_i \le 500\,000\,000$,$1 \le t_i \le 1\,000\,000$),以空格分隔。这三个数表示第 $i$ 家商店位于第 $x_i$ 条 v-street 和第 $y_i$ 条 h-street 的交汇处,且卡车每天向该商店配送货物 $t_i$ 次。

输出格式

标准输出的第一行也是唯一一行应包含两个整数 $x_m$ 和 $y_m$,以空格分隔,表示仓库的最佳位置,即第 $x_m$ 条 v-street 和第 $y_m$ 条 h-street 的交汇处。如果有多个最佳解,程序可以任意选择其中一个。

样例

输入 1

3
2 2 1
6 2 1
4 6 1

输出 1

4 4

说明

下图展示了该样例。带编号的点是商店。点是仓库的最佳位置。

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.