Pagini recente » Cod sursa (job #1440087) | Cod sursa (job #2234269) | Cod sursa (job #2493906) | Cod sursa (job #1802280) | Cod sursa (job #295620)
Cod sursa(job #295620)
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.