Cod sursa(job #275825)

Utilizator MBlueGheorghevici Mihai MBlue Data 10 martie 2009 18:10:29
Problema Transport Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.98 kb
var f : text;
    s : array[1..16000] of integer;
    max,i,n,k,p,cmax,j,ctest,aux : integer;
begin
     assign(f,'transport.in');
     reset(f);
     read(f,n,k,s[1]);
     max := s[1];
     for i := 2 to n do begin
         read(f,s[i]);
         if s[i] > max then
            max := s[i];
     end;
     cmax := max-1;
     aux := 1;
     repeat
           cmax := cmax +1;
           i := 1;
           p := 0;
           while i < n do begin
                 i := aux;
                 ctest := s[i];
                 p := p+1;
                 for j := i+1 to n do begin
                     if (ctest + s[j]) <= cmax then begin
                        ctest := ctest + s[j]  ;
                        aux := j;
                        end
                        else break;
                 end;
                 {i := j;}
           end;
     until p <= k;
     close(F);
     assign(f,'transport.out');
     rewrite(f);
     write(f,cmax);
     close(f);
end.