Cod sursa(job #276278)

Utilizator johsonsbabiJohnsons Babi Minune johsonsbabi Data 11 martie 2009 00:42:47
Problema Transport Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.65 kb
var f : text;
    c : array[1..16000] of integer;
    n,k,max,i,t : integer;
    s:longint;
begin
assign(f,'transport.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;
t := -1;
while t < 1 do begin
      t := k;
      s := 0;
      i := 1;
      while (i <= n) and (t >= 1) do begin
          s := s + c[i];
          if (s > max) then begin
             t := t - 1;
             s := c[i];
          end;
          i := i + 1;
      end;
      max := max + 1;
end;
close(F);
assign(f,'transport.out');
rewrite(f);
write(f,max - 1);
close(f);
end.