Anya and Ghosts - CodeForces 508 C 水题

Anya and Ghosts
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 wi seconds after midnight, all wi'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.

Input

The first line contains three integers mtr (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 wi (1 ≤ i ≤ m1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.

Output

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.

Sample test(s)
input
1 8 3
10
output
3
input
2 10 1
5 8
output
1
input
1 1 3
10
output
-1

题意:一个人一秒钟可以点一根蜡烛,每个魔鬼来的时候需要点至少r根蜡烛,问他至少需要点多少蜡烛。

思路:首先t

AC代码如下:

#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
struct node
{
    int val;
    bool operator<(const node a)const
    {
        return a.val qu;
int T,t,n,m,w[1010],maxn,light[1010],num,sum;
void solve()
{
    int i,j,k;
    scanf("%d%d%d",&n,&t,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&w[i]);
    }
    sort(w+1,w+1+n);
    if(t



你可能感兴趣的:(CodeForces,水题)