Cod sursa(job #276271)

Utilizator johsonsbabiJohnsons Babi Minune johsonsbabi Data 11 martie 2009 00:23:07
Problema Transport Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.69 kb
var f : text;
    c : array[1..16000] of integer;
    n,k,max,i,t : integer;
    s:longint;
begin
assign(f,'transp~1.in');
reset(f);
read(f,n,k,c[1]);
max := c[1];
for i := 2 to n do begin
    read(f,c[i]);
  	if c[i] > max then
       max := c[i];
end;
while true do begin
      t := k;
      s := 0;
      for i := 1 to n do begin
          s := s + c[i];
          if (s > max) then begin
             t := t - 1;
             s := c[i];
          end;
          if (t < 1) then begin
             break;
          end;
      end;
      if (t >= 1) then break
      else max := max + 1;
end;
close(F);
assign(f,'transport.out');
rewrite(f);
write(f,max);
close(f);
end.