Pagini recente » Cod sursa (job #1694675) | Cod sursa (job #2601536) | Cod sursa (job #2311445) | Cod sursa (job #1624532) | Cod sursa (job #1663161)
var n,k,i,j,m,s,t,r,max:longint;
a:array[1..16000] of longint;
begin
assign(input,'transport.in');
assign(output,'transport.out');
reset(input);
rewrite(output);
read(n,k);
s:=0;
for i:=1 to n do begin
read(a[i]);
s:=s+a[i];
end;
r:=1;
while t<>k do begin
m:=(r+s) div 2;
// writeln(r,' ',m,' ',s);
t:=1;
j:=0;
max:=0;
for i:=1 to n do begin
if j+a[i]<=m then begin
j:=j+a[i];
end else begin
inc(t);
j:=a[i];
end;
end;
if t<k then s:=m
else r:=m;
end;
write(m);
end.