您的位置:首页 > 其它

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

2015-08-02 14:40 597 查看
思路:由于一个candle只能覆盖t,所以对某一时刻w[i],最早的candle点亮时间不超过w[i] - t。否则w[i]时刻该candle已经熄灭。

所以对每个w[i],统计w[i] - t ~ w[i] - 1之间有多少根蜡烛被点亮即可。若已有r个candle,不做任何处理。否则,由近及远点亮需要的candle。

代码如下:

#include <cstdio>
using namespace std;
#define N 605
int w
;
bool candle
;

int main(){
int n, t, r, x;
scanf("%d %d %d", &n, &t, &r);
for(int i = 1; i <= n; ++i)
scanf("%d", &x), w[i] = x + 300;
if(t < r)
printf("-1\n");
else{
int ans = 0;
bool ok = true;
for(int i = 1; i <= n && ok; ++i){
int cnt = 0;
for(int j = w[i] - 1; j >= w[i] - t; --j){
if(candle[j])
cnt ++;
}
if(cnt < r){
for(int j = w[i] - 1; j >= w[i] - t && cnt < r; --j){
if(!candle[j])
cnt ++, ans ++, candle[j] = true;
}
if(cnt < r)
ok = false;
}
}
if(ok)
printf("%d\n", ans);
else
printf("-1\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: