QOJ.ac

QOJ

Time Limit: 2.5 s Memory Limit: 512 MB Total points: 110

#13364. 摩天大楼

Statistics

Domagoj 正在伦敦的大城市里!此时,他面前有一排高耸的摩天大楼,他想拍一张照片来纪念这一刻。

这排摩天大楼可以用一个包含 $n$ 个数字的序列 $h_1, h_2, \dots, h_n$ 来表示,其中数字 $h_i$ 代表第 $i$ 座摩天大楼的高度。Domagoj 将会拍摄一段连续的摩天大楼子序列。为了捕捉更多城市的风光,他希望拍摄至少 $k$ 座摩天大楼。

Domagoj 对照片的美感有着独特的理解。当照片中有高大的摩天大楼时,他会感到非常高兴,但如果它们的高度有一个较大的公约数,他会更高兴!如果我们用 $h_l, \dots, h_r$ 来标记照片中连续摩天大楼的高度,并用 $g$ 表示所选高度的最大公约数,那么 Domagoj 将这张照片的美感定义为 $g \cdot (h_l + \dots + h_r)$。

请帮助 Domagoj 确定包含至少 $k$ 座摩天大楼的照片中,最美的那张照片的美感是多少!

输入格式

第一行包含两个整数 $n, k$ ($1 \le k \le n \le 10^6$),分别表示摩天大楼的数量和 $k$ 的值。

第二行包含 $n$ 个整数 $h_1, h_2, \dots, h_n$ ($1 \le h_i \le 10^6$),按顺序表示摩天大楼的高度。

输出格式

输出一行,包含题目要求的结果。

子任务

子任务 分值 数据范围
1 11 $n, k \le 100$
2 22 $n, k \le 5000$
3 27 $h_i \le 100$
4 18 $n, k \le 5 \cdot 10^4$
5 32 无附加限制

样例

输入 1

6 2
2 1 4 4 4 2

输出 1

48

说明 1

Domagoj 拍摄了摩天大楼 $(4, 4, 4)$,因此总美感为 $4 \cdot (4 + 4 + 4) = 48$。

输入 2

4 1
7 3 9 4

输出 2

81

说明 2

Domagoj 只拍摄了摩天大楼 $(9)$,因此总美感为 $9 \cdot 9 = 81$。

Figure 1. Domagoj 正在伦敦的大城市里拍摄摩天大楼

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.