Codeforces 508C Anya and Ghosts

Source: Internet
Author: User

Anya and GhostsTime limit:2000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 508C

Description

Anya loves to watch horror movies. In the best traditions of horror, she'll be visited By  m  ghosts tonight. Anya have 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 would happen C5>wi seconds after midnight, all wiam is distinct. Each visit lasts exactly one second.

What's the minimum number of candles Anya should use so this during each visit in least R Candles are bu Rning? Anya can start to light a candle at any time this is an integer number of seconds from midnight, possibly, at the time before Midnight. That's means, she can start to light a candle integer number of seconds before midnight or integer number of seconds AF ter a midnight, or in other words with any integer moment of time.

Input

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 wi (1≤ im, 1≤ wi ≤300), the i-th of them repesents at what second after the Midni Ght the i-th ghost would come. All wi' s is distinct, they follow in the strictly increasing order.

Output

If It is possible to make at least R Candles burn during all visit, then print the minimum number of cand Les that Anya needs to light for that.

If is impossible, print -1.

Sample Input

Input
1 8 3
10
Output
3
Input
2 10 1
5 8
Output
1
Input
1 1 3
10
Output
-1

Hint

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

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

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

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 are-1, since during each second at most one candle can burn but Anya needs three Candles to light up the the-the-moment when the ghost comes.

1#include <stdio.h>2#include <string.h>3 4 intMain ()5 {6     intM,t,r;7     intw[305];8     intvis[1005],lig[1005];9     inti,j,flg,s,k;Ten      while(SCANF (" %d%d%d", &m,&t,&r)! =EOF) One     { Aflg=1; s=0; -memset (Lig,0,sizeof(Lig)); -memset (Vis,0,sizeof(Vis)); the          for(i=1; i<=m;i++) -         { -scanf"%d",&w[i]); -         } +         if(t<R) -         { +flg=0; A         } at         Else -         { -s=R; -              for(i=w[1]-1; i>=0&& i>=w[1]-r;i--) -vis[i]=1; -              for(i=1; i<=r;i++) in             { -                  for(j=w[1];j<=w[1]+t-i;j++) to                 { +lig[j]++; -                 } the             } *              for(i=2; i<=m;i++) $             {Panax Notoginseng                 if(flg==0) -                      Break; the                 if(lig[w[i]]>=R) +                     Continue; A                 intww=r-Lig[w[i]]; the                  for(j=w[i]-1; j>=w[i]-ww;j--) +                 { -                     if(vis[j]==1) $                     { $flg=0; Break; -                     } -vis[j]=1; thes++; -                 }Wuyi                  for(k=1; k<=ww;k++) the                 { -                      for(j=w[i];j<=w[i]+t-k;j++) Wu                     { -lig[j]++; About                     } $                 } -             } -         } -         if(flg==0) Aprintf"-1\n"); +         Else theprintf"%d\n", s); -     } $     return 0; the } the  the  the  -  in  the  the             /*For (i=0;i<=20;i++) About printf ("%d", vis[i]); the printf ("\ n"); the For (i=0;i<=20;i++) the printf ("%d", Lig[i]); + printf ("\ n");*/
View Code

Codeforces 508C Anya and Ghosts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.