Cod sursa(job #295620)

Utilizator Cristian_BBerceanu Cristian Cristian_B Data 3 aprilie 2009 15:10:13
Problema Transport Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.64 kb
var s,ct,i,j,n,k:longint;
    l,max:int64;
    ok:boolean;
    v:Array[1..16000] of longint;
    f,g:text;
procedure load;
begin
assign(f,'transport.in');
reset(f);
readln(f,n,k);
for i:=1 to n do
readln(f,v[i]);
close(f);
assign(g,'transport.out');
rewrite(g);


end;
BEGIN
load;
max:=v[1];
for i:=2 to n do
if max<v[i] then max:=v[i];
l:=max;
ct:=0;
i:=1;
while (ct<k) do
begin
 s:=0;ok:=true;
 while (i<=n) and (ok=true) do
 begin
  s:=s+v[i];
  if s+v[i+1]>l then ok:=false;
  i:=i+1;
 end;
 ct:=ct+1;
 if (ct>=k) and (i<n) then
 begin
  l:=l+1;
  ct:=0;
  i:=1;
 end;
end;
writeln(g,l);
close(g);
END.