QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 64 MB مجموع النقاط: 110

#13591. 交响乐

الإحصائيات

几乎没有人相信作曲家 Marin 的才华。具体来说,直到他创作出他的第九交响曲的那一天,人们才开始改变看法。

交响曲可以表示为一系列整数频率。为了证明自己的才华,并表明这部交响曲不仅仅是众多平庸之作中的一部,Marin 决定将其与历史上最伟大的音乐家 Stjepan 的古老交响曲《小夜曲狂欢节》("Little Night Fiesta")进行对比。冥冥之中,这两部交响曲的长度都等于 $N$。

Marin 通过将两部交响曲写在一张纸上,一上一下进行对比。交响曲的差异度定义为对应频率绝对差的总和。长度为 $N$ 的交响曲 $A$ 和 $B$ 的差异度为:

$$\sum_{i=1}^{N} |A_i - B_i|$$

在对比两部交响曲之前,Marin 会做两件事。首先,他会通过将每个频率加上一个整数 $X$ 来调制他的交响曲。然后,他会将不超过 $K$ 个频率修改为其他任意频率值,因为像所有顶尖创作者一样,他在梦中得到了启示。

Marin 将选择 $X$ 并修改最多 $K$ 个频率,使得他的交响曲与 Stjepan 的尽可能相似,即定义的差异度最小。帮助 Marin 计算与 Stjepan 交响曲的最小可能差异度。

输入格式

第一行包含整数 $N$ 和 $K$($1 \le N \le 100\,000$,$0 \le K \le N$),含义如题面所述。

第二行包含 $N$ 个整数 $A_i$($-1\,000\,000 \le A_i \le 1\,000\,000$),表示 Marin 交响曲的频率。

第三行包含 $N$ 个整数 $B_i$($-1\,000\,000 \le B_i \le 1\,000\,000$),表示 Stjepan 交响曲的频率。

输出格式

在唯一的一行中输出 Marin 和 Stjepan 交响曲之间的最小可能差异度。

子任务

在占总分 40% 的测试数据中,满足 $K = 0$。

样例

输入样例 1

3 0
1 2 3
4 5 7

输出样例 1

1

输入样例 2

3 1
1 2 3
4 5 7

输出样例 2

0

输入样例 3

4 1
1 2 1 2
5 6 7 8

输出样例 3

2

说明

样例 2 解释:如果 Marin 将他的交响曲调制 $X = 3$(即每个频率加上 3,得到 $4, 5, 6$),并将最后一个频率修改为 7(得到 $4, 5, 7$),那么他的交响曲将与 Stjepan 的完全相同,因此所需的差异度为 0。

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.