99042 - 拯救小鸡

#include<bits/stdc++.h>

using namespace std; 

#define N 10000
int n,t,x,ti[N+3]; 
int vis[2*N+3]; 

int main(){
	freopen("chick.in","r",stdin); 
	freopen("chick.out","w",stdout);  
	scanf("%d%d%d",&n,&t,&x); 
	for(int i=1;i<=n;i++) 
		scanf("%d",&ti[i]) ;
	if(t<x) {
		cout<<-1<<endl;
		return 0; 
	}
	for(int i=1;i<=n;i++){
		int num=0; 
		for(int j=ti[i]-1;j>=ti[i]-t;j--)
			num+=vis[j+N]; 
		if (num<x){
			for(int j=ti[i]-1;j>=ti[i]-t;j--) 
				if(!vis[j+N]){
					vis[j+N]=1; 
					if(++num==x) break; 
				}
		}
	}
	int ans=0; 
	for(int i=0;i<=2*N;i++) 
		ans+=vis[i]; 
	cout<<ans<<endl; 
	return 0; 
}