CF508C
liuzhongrui · · 题解
思路
我们先来判断输出 -1 的情况,题目中说到每根蜡烛可以燃烧 -1 即可。
接下来的情况都是合法的了。我们逐个读入每个鬼魂的到达时间
Code
十分简短。
#include<bits/stdc++.h>
using namespace std;
int a[1010];
int m,t,r;
int main() {
scanf("%d%d%d",&m,&t,&r);
if(t<r) {
puts("-1");
return 0;
}
int st=0,ed=0,ans=0;;
while(m--) {
int w;
scanf("%d",&w);
while(st<ed&&a[st]<w) st++;
for(int i=w-r+ed-st; i<w; i++){
a[ed++]=i+t;
ans++;
}
}
printf("%d\n",ans);
return 0;
}