QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 256 MB 总分: 100

#10166. 动画

统计

Aizhan 正在观看《咒术回战》的最后一集。该集时长恰好为 $n$ 秒。在每一时刻,她都知道自己的兴趣水平 $I(t)$。幸运的是,函数 $I(t)$ 是一个连续的分段线性函数。她已知在整数时刻的兴趣值:$I(0), I(1), I(2), I(3), \dots, I(n)$。为了得到非整数时刻的值,她可以通过连接每两个相邻的整数点 $(x, I(x))$ 和 $(x+1, I(x+1))$ 来绘制函数 $I$ 的图像。观看某一段视频片段的兴趣值即为该片段下函数图像与坐标轴围成的面积。

这个视频播放器非常奇怪。它只有两个按钮:快进和快退。第一个按钮会将视频向前跳转 $k$ 秒,第二个按钮会将视频向后跳转 $k$ 秒。因此,视频无法暂停。

经过反复试验,Aizhan 注意到,如果跳转后超出了视频的时间范围,则无法进行快进或快退;换句话说,她必须始终保持在时间区间 $[0, n]$ 内(无法进行领域扩张)。第二个特殊之处在于,当她看完这一集时,两个按钮的使用次数必须相等;否则,她的电脑会爆炸,这可一点也不好玩。

Aizhan 在不使用按钮的情况下看完了这一集,她获得的累积兴趣值就是函数 $I$ 图像下的总面积。现在,她想知道如果最优地使用这些按钮,她能获得的最大累积兴趣值是多少。

注意,按钮可以在任何时刻使用,即使是在非整数时刻。只要在看完这一集时,快进按钮和快退按钮的使用次数相同,按钮就可以使用任意多次。

输入格式

第一行包含两个整数 $n$ 和 $k$ ($1 \le k \le n \le 10^5$):视频的时长和播放器的特性参数。

第二行包含 $n+1$ 个整数 $I(0), I(1), I(2), I(3), \dots, I(n)$ ($0 \le I(i) \le 10^5$):所有整数时刻的兴趣水平。

输出格式

输出一行一个数字:问题的答案。

如果你的答案的绝对误差或相对误差不超过 $10^{-6}$,则被视为正确。

样例

样例输入 1

2 1
0 1 2

样例输出 1

3.000000

样例输入 2

2 1
0 5 0

样例输出 2

7.500000

说明

在第一个样例中,Aizhan 可以在时刻 $0$ 使用快进按钮,观看视频的时间区间 $[1, 2)$,然后快退以再次观看时间区间 $[1, 2)$。

注意,Aizhan 观看了两次时间区间 $[1, 2)$,该区间在图像下的面积为 $1.5$。因此,累积兴趣值为 $3.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.