QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#10145. 雕像

Statistics

<Link /> 想要得到一张新的 C chart,它只能在 The Isle of <meta> 上的 The Temple of <element> 内部找到。为了进入神庙,他必须先解开一个谜题。

<Link /> 必须首先进入一个 $T$ 维平面,因此空间中的每个点都可以由一个长度为 $T$ 的数组表示:$[x_1,x_2,x_3, \dots, x_T]$。在这个平面上,有 $N$ 个编号从 $1$ 到 $N$ 的固定雕像,以及 $Q$ 个编号从 $1$ 到 $Q$ 的移动雕像。<Link /> 最多可以进行 $K$ 次移动:他可以选择任意一个 移动 雕像和一个坐标轴,并将该雕像沿该方向移动恰好一个单位。也就是说,该雕像的坐标将变为 $[x_1,x_2, \dots,x_i−1,\dots,x_T]$ 或 $[x_1,x_2,\dots,x_i+1,\dots, x_T]$。

为了解锁 The Temple of <element> 的入口,他必须以这样一种方式移动 移动 雕像,使得所有 移动 雕像与所有 固定 雕像之间的曼哈顿距离之和最小化。

两个 $T$ 维点 $[x_1,x_2,\dots,x_T]$ 和 $[y_1,y_2,\dots,y_T]$ 之间的曼哈顿距离定义为:

$dist([x_1, x_2, \dots, x_T], [y_1, y_2, \dots, y_T]) = \displaystyle \sum_{i = 1}^{T} |x_i - y_i|$

设 $s$ 为每个 固定 雕像坐标的数组,$m$ 为在最优地进行至多 $K$ 次移动后,每个 移动 雕像坐标的数组。你需要计算:

$\displaystyle \sum_{i = 1}^{N} \sum_{j = 1}^{Q} dist(s_i, m_j)$

输入格式

输入的第一行包含整数 $N, T, K$,分别代表固定雕像的数量、维度数量以及 <Link /> 可以进行的移动次数。

接下来的 $N$ 行,每行包含 $T$ 个空格分隔的整数。其中第 $i$ 行表示第 $i$ 个 固定 雕像的坐标。

下一行包含一个整数 $Q$,代表 移动 雕像的数量。

接下来的 $Q$ 行,每行包含 $T$ 个空格分隔的整数,以与 固定 雕像相同的方式表示每个 移动 雕像的坐标。

输出格式

输出一个整数,表示在进行至多 $K$ 次移动后,所有 固定 雕像到所有 移动 雕像的曼哈顿距离之和的最小值。

数据范围

  • $1 \leq N, Q \leq 100 \ 000$
  • $1 \leq T \leq 10$
  • $1 \leq K \leq 10^{15}$
  • 所有坐标均为 $0$ 到 $10^9$ 之间的整数。
  • 保证答案在 64 位有符号整数范围内。
# 分值 数据范围
1 7 $T = Q = 1$
2 10 $N, Q, K \leq 100$
3 12 $N, Q \leq 50$
4 28 $T = 1$
5 17 $Q = 1$
6 26 无额外限制

样例

输入格式 1

3 2 7
8 1
2 0
0 3
2
10 2
2 6

输出格式 1

29

输入格式 2

6 4 200
12 1 19 10
45 3 42 44
42 32 40 41
39 12 32 47
35 18 40 20
38 14 25 1
3
34 10 7 9
29 32 21 50
16 36 18 38

输出格式 2

708

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.