Cod sursa(job #19041)

Utilizator izso88istvan zsolt izso88 Data 18 februarie 2007 18:14:13
Problema Ghiozdan Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.37 kb
const gmaxc=7500;
      nmaxc=2000;

var tomb:array[0..gmaxc,0..nmaxc] of byte;
    t:text;
    N,G,i,j,co,u:longint;


begin
     assign(t,'ghiozdan.in');
     reset(T);
      read(t,N);
      read(t,G);
      for i:=1 to n do read(t,tomb[0,i]);
     closE(T);

     for i:=1 to gmaxc do for j:=1 to nmaxc do tomb[i,j]:=0;

     for i:=1 to g do begin

       j:=0;
       while (j<n) and ((tomb[i,0]>2) or (tomb[i,0]=0)) do
        begin
        inc(j);
         co:=i-tomb[0,j];

         if co>0 then begin if (tomb[co,j]=0) and (tomb[co,0]>0) then
                        if ((tomb[co,0]+1)<tomb[i,0]) or (tomb[i,0]=0) then
                       begin
                        for u:=0 to n do tomb[i,u]:=tomb[co,u];
                         tomb[i,j]:=1;
                         inc(tomb[i,0]);
                       end;
         end
         else
         if co=0 then  begin
                        for u:=0 to n do tomb[i,u]:=0;
                         tomb[i,j]:=1;
                         inc(tomb[i,0]);
                       end;
       

        end;
     end;

     u:=g;
     while tomb[u,0]=0 do u:=u-1;
     assign(t,'ghiozdan.out');
     rewrite(T);
      write(t,u,' ');
      writeln(t,tomb[u,0]);
      for i:=1 to n do
       if tomb[u,i]=1 then
                          writeln(t,tomb[0,i]);
     close(t);


end.