Cod sursa(job #253916)

Utilizator Teodor94Teodor Plop Teodor94 Data 6 februarie 2009 13:37:28
Problema Caramizi Scor 0
Compilator fpc Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 1 Marime 0.61 kb
var f,g:text;
    n,m,s,i,j,k,x:longint;
    c,a:array[0..200000] of longint;
begin
  assign(f,'caramizi.in'); reset(f);
  assign(g,'caramizi.out'); rewrite(g);
  read(f,n,m);
  s:=0;
  for i:=1 to n do begin read(f,c[i]); s:=s+c[i]; end;
  for i:=1 to m do
    begin
      read(f,x);
      if s mod x=0 then writeln(g,s div x)
                   else
      begin
         for j:=2 to s do
           begin
             a:=c;
             for k:=1 to n do
               if a[k]>j then a[k]:=a[k]-j
                         else break;

           end;
      end;
    end;
  close(f); close(g);
end.