Cod sursa(job #640579)

Utilizator ion824Ion Ureche ion824 Data 25 noiembrie 2011 23:12:48
Problema Zombie Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.41 kb
Program zombie;
  var t:array[1..1000005]of longint;
      b1:array[1..1 shl 17]of char;
      s:string;
      p,i,cost,j,l,d,n,k:longint;
      f,g:text;

Function citire:longint;
  var aux,i:longint;
begin
  i:=1;
  while(i<=n)do begin
  aux:=0;
  while(p<=l) and (s[p]>='0') and (s[p]<='9')do begin
                           aux:=aux*10+(ord(s[p])-48);
                           if(p=l)then begin
                              read(f,s);
                              l:=length(s);
                              p:=0;
                              end;

                           inc(p);
                          end;
  while (p<=l) and ((s[p]<'0') or (s[p]>'9') and (s<>'')) do begin
                              inc(p);
                           if(p>l)then begin
                               read(f,s);
                               l:=length(s);
                               p:=1;
                              end;

                              end;
        t[i]:=aux; inc(i);
        end;
    end;

Begin
  assign(f,'zombie.in'); settextbuf(f,b1); reset(f); readln(f,d,n,k);
  read(f,s); p:=1; l:=length(s); cost:=0;
  citire;
  i:=1;
  while(i<n) do begin
       j:=i+1;
       while((t[j]-t[i]<d) and (j<=n))do inc(j);
       if(k<j-i)then cost:=cost+k else cost:=cost+j-i;
       i:=j;
       end;
  assign(g,'zombie.out'); rewrite(g); write(g,cost); close(g);
end.