Cod sursa(job #275805)

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