Cod sursa(job #645066)

Utilizator halianStefanca Stefan halian Data 8 decembrie 2011 11:14:07
Problema Zombie Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <stdio.h>
#define FI fopen("zombie.in","r")
#define FO fopen("zombie.out","w")
#define min(a,b) (a<b?a:b)

long int N,D,K,zombie[1000010],vec[1000010],rez[1000010];

void cit (FILE *f=stdin) {
	int i,j=0,t;
	fscanf(f,"%li%li%li",&D,&N,&K);
	for(i=0;i<N;++i) {
		fscanf(f,"%li",&zombie[i]);
		while(zombie[j]<zombie[i]-D)
			++j;
		for(t=j;t<=i;++t) {
			++vec[t];
		}
	}
}

int main(){
	long i;
	cit(FI);
	for(i=N-1;i>=0;--i)
		rez[i]=min(rez[i+1]+1,rez[i+vec[i]]+K);
	fprintf(FO,"%li",rez[0]);
	return 0;
}