CodeForces 508C Anya and Ghosts
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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 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 ≤ i ≤ m, 1 ≤ 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 Input
1 8 3
10
3
2 10 1
5 8
1
1 1 3
10
-1
Hint
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.
#include <stdio.h>
#include <string.h> int main()
{
int m,t,r;
int w[];
int vis[],lig[];
int i,j,flg,s,k;
while(scanf("%d %d %d",&m,&t,&r)!=EOF)
{
flg=;s=;
memset(lig,,sizeof(lig));
memset(vis,,sizeof(vis));
for(i=;i<=m;i++)
{
scanf("%d",&w[i]);
}
if(t<r)
{
flg=;
}
else
{
s=r;
for(i=w[]-;i>= && i>=w[]-r;i--)
vis[i]=;
for(i=;i<=r;i++)
{
for(j=w[];j<=w[]+t-i;j++)
{
lig[j]++;
}
}
for(i=;i<=m;i++)
{
if(flg==)
break;
if(lig[w[i]]>=r)
continue;
int ww=r-lig[w[i]];
for(j=w[i]-;j>=w[i]-ww;j--)
{
if(vis[j]==)
{
flg=;break;
}
vis[j]=;
s++;
}
for(k=;k<=ww;k++)
{
for(j=w[i];j<=w[i]+t-k;j++)
{
lig[j]++;
}
}
}
}
if(flg==)
printf("-1\n");
else
printf("%d\n",s);
}
return ;
} /*for(i=0;i<=20;i++)
printf("%d ",vis[i]);
printf("\n");
for(i=0;i<=20;i++)
printf("%d ",lig[i]);
printf("\n");*/
CodeForces 508C Anya and Ghosts的更多相关文章
- CodeForces 508C Anya and Ghosts 贪心
做不出题目,只能怪自己不认真 题目: Click here 题意: 给你3个数m,t,r分别表示鬼的数量,每只蜡烛持续燃烧的时间,每个鬼来时要至少亮着的蜡烛数量,接下来m个数分别表示每个鬼来的时间点( ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟
C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心
C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF Anya and Ghosts (贪心)
Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 【codeforces 508C】Anya and Ghosts
[题目链接]:http://codeforces.com/contest/508/problem/C [题意] 每秒钟可以点一根蜡烛; 这根蜡烛会燃烧t秒; 然后会有m只鬼来拜访你; 要求在鬼来拜访你 ...
- [CF #288-C] Anya and Ghosts (贪心)
题目链接:http://codeforces.com/contest/508/problem/C 题目大意:给你三个数,m,t,r,代表晚上有m个幽灵,我有无限支蜡烛,每支蜡烛能够亮t秒,房间需要r支 ...
- Codeforces 525E Anya and Cubes
http://codeforces.com/contest/525/problem/E 题意: 有n个方块,上面写着一些自然数,还有k个感叹号可用.k<=n 你可以选任意个方块,然后选一些贴上感 ...
- codeforces 518C. Anya and Smartphone
C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- Power Gating的设计(模块)
Switching Fabric的设计: 三种架构:P沟道的switch vdd(header switch),N沟道的switch vss(footer switch),两个switch. 但是如果 ...
- 八、Java基础---------基本语法
一.学习Java注意的细节: 1.1 Java语言拼写上严格区分大小写: 1.2 一个Java源文件里可以定义多个Java类,但其中最多只能有一个类被定义成public类: 1.3 若源文件中 ...
- NOIP201205Vigenère密码
NOIP201205Vigenère密码 [问题描述] 16 世纪法国外交家Blaise de Vigenère设计了一种多表密码加密 ...
- 如何对HashMap按键值排序
Java中HashMap是一种用于存储“键”和“值”信息对的数据结构.不同于Array.ArrayList和LinkedLists,它不会维持插入元素的顺序. 因此,在键或值的基础上排序HashMap ...
- LoadRunner11下载以及详细破解说明【最新】
Loadrunner11破解所需两个dll文件以及自动删除注册表工具,使用方法见附件readme.也可安装网上的办法,手动删除注册表项. 下载破解文件lm70.dll和mlr5lprg.dll lm7 ...
- AC68U 内Linux 终端前后的切换,终端挂起和恢复
ssh 登录终端后, 如果想切换到本地上来, 可以按: -,Ctrl+Z 如果要恢复到远程端,则命令: fg
- vsftpd匿名用户只能上传不能下载
目的 搭建一台FTP服务器,供学生上传作业使用. 要求 1.学生可以直接访问FTP服务器,无需登录: 2.只能上传文件,不能创建文件夹.重命名.删除等: 3.不能下载文件(防抄袭): 4.不能在线查看 ...
- python两个 list 交集,并集,差集的方法+两个tuple比较操作+两个set的交集,并集,差集操作+两个dict的比较操作
转自:http://blog.chinaunix.net/uid-200142-id-3992553.html 有时候,为了需求,需要统计两个 list 之间的交集,并集,差集.查询了一些资料,现在总 ...
- Dynamics AX 2012 R2 Business Connector Error
6.0: AxCryptoClient - New encryption key created 6.0: Unable to InitializeSession. 6.0: No built-in ...
- hobby
如果把战争的原则凝缩为一个词,那就是集中. 人生有三把钥匙, 接受. 改变. 离开.不能接受,那就改变,不能改变,那就离开. 少问别人为什么,多问自己凭什么. 太平自古将军定,不许将军见太平