QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100

#2698. 翻转流

統計

600 多年来,沙漏一直是一种广为人知的计时工具。沙漏由两个上下排列的玻璃瓶组成,中间由一个狭窄的通道连接。沙漏内部的沙子会缓慢地从上方的瓶子流向下方。沙漏通常是对称的,因此无论朝向如何,沙子流完所需的时间总是相同的。在本题中,我们假设沙子的流速是一个已知的常数,且不取决于上半部分沙子的数量或分布。

Hourglass by nile on Pixabay

你的朋友 Helen 很无聊,一直在玩她的沙漏。在时间 $0$ 时,所有的沙子都在下半部分。Helen 多次翻转了沙漏,并记录了她翻转的所有时刻。从当前时间开始,她还需要等待多少秒,所有的沙子才能回到下半部分?

输入格式

输入包含: 一行,包含三个整数 $t, s$ 和 $n$,其中: $t$ ($1 \le t \le 10^6$) 是当前时间; $s$ ($1 \le s \le 10^6$) 是沙漏中沙子的总量(单位:克); $n$ ($1 \le n \le 1000$) 是沙漏被翻转的次数。 * 一行,包含 $n$ 个整数 $a_1, \dots, a_n$ ($0 < a_1 < \dots < a_n < t$),表示翻转沙漏的时刻。

所有时间均以秒为单位。你可以假设沙子以每秒 $1$ 克的恒定速率从上方流向下方。

输出格式

输出从时间 $t$ 开始,沙漏流完所有沙子所需的时间(单位:秒)。

样例

输入格式 1

10 7 2
4 9

输出格式 1

4

输入格式 2

2000 333 3
1000 1250 1500

输出格式 2

0

输入格式 3

100 10 5
15 20 93 96 97

输出格式 3

5

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.