Codeforces Round #288 (Div. 2) C. Anya and Ghosts,

Source: Internet
Author: User

Codeforces Round #288 (Div. 2) C. Anya and Ghosts,

C. Anya and Ghoststime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Anya loves to watch horror movies. In the best traditions of horror, she will be visitedMGhosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactlyTSeconds. 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 exactlyTSeconds and then goes out and can no longer be used.

For each ofMGhosts Anya knows the time at which it comes:I-Th visit will happenWISeconds after midnight, allWI'S are distinct. Each visit lasts exactly one second.

What is the minimum number of candles Anya shocould use so that during each visit, at leastRCandles 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 integersM,T,R(1 digit ≤ DigitM, Bytes,T, Bytes,RLimit ≤ limit 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that shoshould burn during each visit.

The next line containsMSpace-separated numbersWI(1 digit ≤ DigitILimit ≤ limitM, 1 limit ≤ limitWILimit ≤ limit 300),I-Th of them repesents at what second after the midnightI-Th ghost will come. AllWI'S are distinct, they follow in the strictly increasing order.

Output

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

If that is impossible, print your-records 1.

Sample test (s) input
1 8 310
Output
3
Input
2 10 15 8
Output
1
Input
1 1 310
Output
-1

After midnight, there will be m ghosts to visit and give them time points to visit. Now there are many candles, each of which can burn for t seconds, it takes one second for Anya to burn a candle. For example, if Anya burns a candle at the p moment, the candle will be in the p + 1 ~ The p + t period burns and Anya can light candles at any time. Now, it is required that r candles be lit when a ghost visits and ask Anya how many candles should be kept at least.

Idea: Use a struct to represent a candle, record the time period when the candle is burning, scan the ghost visit time, and judge which candles are burning at the time of come [I, if there is no combustion, You need to ignite it before the come [I] moment. The closer it is to come [I], the better, so you can push forward from the come [I]-1 moment.

Code:

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <string> # include <map> # include <stack> # include <vector> # include <set> # include <queue> # pragma comment (linker, "/STACK: 102400000,102400000") # define maxn 1005 # define MAXN 2005 # define mod 1000000009 # define INF 0x3f3f3f # define pi acos (-1.0) # define eps 1e-6 # define lson rt <1, l, mid # define rson rt <1 | 1, mid + 1, rtypedef long ll; using namespace std; struct St {int s, e;} st [maxn]; int m, t, r; int come [maxn]; int dian [maxn]; int main () {while (~ Scanf ("% d", & m, & t, & r) {memset (dian, 0, sizeof (dian )); for (int I = 0; I <r; I ++) {st [I]. s =-1; st [I]. e =-1 ;}for (int I = 0; I <m; I ++) scanf ("% d", & come [I]), come [I] + = 300; // Add 300 int ans = 0 in advance when the ghost arrives; // The minimum candle count int ff = 1; // mark whether it meets the requirements for (int I = 0; I <m; I ++) // traverse the moment when the ghost arrives {int tt = come [I], ss = come [I]; tt, in this way, the minimum candle for (int j = 0; j <r; j ++) can be used to determine the r and candle {if (st [j]. e <ss) // The j and candle are at the ss moment, that is, the ghost. Before the arrival of the soul, it will burn up. You need to click another {int flag = 0; // mark whether the candle can be lit. while (tt + t> = ss) {if (! Dian [tt]) // you can click {st [j] at the tt moment. s = tt; // record the burning period of the j and candle. st [j]. e = tt + t; dian [tt] = 1; // mark. ans ++ cannot be clicked in the future; // The number of candles increases from flag to 1; break ;} tt --; // tt push forward} tt --; if (! Flag) // ff = 0 cannot be lit; // if (ff) printf ("% d \ n", ans) must be output-1 }}} if (ff) printf ("% d \ n", ans ); else printf ("-1 \ n");} return 0 ;}



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.