Pagini recente » Cod sursa (job #2928436) | Cod sursa (job #1905072) | Cod sursa (job #509278) | Cod sursa (job #974336) | Cod sursa (job #1680775)
program transport;
var max, i, st, dr,s, piv, m : longint;
n, k, r : integer;
a : array[1..16000] of integer;
f : text;
function check(x:longint):boolean;
begin
for i:=1 to n do begin
s:=s+a[i];
if s>m then begin
inc(r);
s:=a[i];
end;
end;
if r<=k then check:=true else check:=false;
end;
begin max:=0;
assign(f,'transport.in');
reset(f);
readln(f, n, k);
for i:=1 to n do begin
readln(f, a[i]);
if a[i]>max then max:=a[i];
end;
close(f);
st:=max;
dr:=256000001;
while st<=dr do begin
piv:=st+(dr-st)div 2;
s:=0; m:=piv;
r:=1;
if check(m) then begin dr:=piv-1; end
else st:=piv+1;
end;
assign(f, 'transport.out');
rewrite(f);
writeln(f, m ); close(f);
end.