CF508C.Anya and Ghosts

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.

For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen w__i seconds after midnight, all w__i's are distinct. Each visit lasts exactly one second.

What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.

安雅喜欢看恐怖电影。按照恐怖片的最佳传统,今晚将有 mm 个幽灵来拜访她。安雅为这些拜访准备了大量的蜡烛,每支蜡烛恰好能持续发光 tt 秒。安雅点燃一支蜡烛需要恰好 1 秒。更准确地说,安雅可以在 1 秒内点燃一支蜡烛,随后这支蜡烛将恰好燃烧 tt 秒,之后熄灭,且无法再次使用。

对于这 mm 个幽灵中的每一个,安雅都知道其到来的时间:第 ii 次拜访发生在午夜之后 wiw_i 秒,所有 wiw_i 互不相同。每次拜访恰好持续 1 秒。

为了让每次拜访发生时,都至少有 rr 支蜡烛正在燃烧,安雅最少需要使用多少支蜡烛?安雅可以在任意整数秒时刻(以午夜为参考点)开始点燃蜡烛,该时刻可以是午夜之前(负数秒),也可以是午夜之后(正数秒),即:她可以在任意整数时刻开始点燃一支蜡烛。

输入格式

The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.

The next line contains m space-separated numbers w__i (1 ≤ i ≤ m, 1 ≤ w__i ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All w__i's are distinct, they follow in the strictly increasing order.

第一行包含三个整数 mm、tt、rr(1 ≤ m, t, r ≤ 3001 \leq m,\,t,\,r \leq 300),分别表示拜访 Anya 的幽灵数量、一支蜡烛的燃烧时长(单位:秒)以及每次幽灵拜访期间至少应同时燃烧的蜡烛数量。

第二行包含 mm 个用空格分隔的整数 wiw_i(1 ≤ i ≤ m1 \leq i \leq m,1 ≤ wi ≤ 3001 \leq w_i \leq 300),其中第 ii 个数表示第 ii 个幽灵在午夜之后第 wiw_i 秒到来。所有 wiw_i 互不相同,且严格递增排列。

输出格式

If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.

If that is impossible, print  - 1.

如果可以保证每次访问时至少有 $ r $ 支蜡烛处于燃烧状态,则输出 Anya 为此需要点燃的蜡烛的最小数量。

否则,输出 −1-1。

输入输出样例

  • 输入#1

    1 8 3
    10

    输出#1

    3
  • 输入#2

    2 10 1
    5 8

    输出#2

    1
  • 输入#3

    1 1 3
    10

    输出#3

    -1

说明/提示

Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.

It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.

In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.

In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.

In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.

安雅可以在幽灵到访的同一秒开始点燃一支蜡烛。但此时这支蜡烛在该次到访中不被视为正在燃烧。

点燃一支蜡烛恰好需要一秒,且仅在该秒结束后,这支蜡烛才被视为处于燃烧状态;也就是说,若安雅在时刻 xx 开始点燃一支蜡烛,则该蜡烛的燃烧时间段为从第 x+1x + 1 秒到第 x+tx + t 秒(含端点)。

在第一个样例测试中,三支蜡烛就足够了。例如,安雅可以在午夜之后的第 33、55 和 77 秒开始点燃这三支蜡烛。

在第二个样例测试中,一支蜡烛就足够了。例如,安雅可以在午夜前一秒(即 −1-1 秒)开始点燃这支蜡烛。

在第三个样例测试中,答案为 −1-1,因为在任意一秒内最多只有一支蜡烛可以处于燃烧状态,而安雅在幽灵到访的时刻需要同时有三支蜡烛在燃烧才能照亮房间。

输入解题思路,AI测评打分。不知道怎么写?

首页