Pagini recente » Cod sursa (job #1784016) | Cod sursa (job #720036) | Cod sursa (job #1987547) | Cod sursa (job #1367489) | Cod sursa (job #2467688)
var maxim,e,n,k,i,last,p,stanga,dreapta,mid:longint;
type vector = array[1..100000] of longint;
var x:vector;
fin,fout:textfile;
function aha(capacitate:longint):boolean;
var i,e,o,p,transp:longint;
begin
transp:=1;
p:=0;
for i:=1 to n do begin
if p+x[i]>capacitate then begin
p:=x[i];
inc(transp);
end
else p:=p+x[i];
end;
if transp>k then aha:=false
else aha:=true;
end;
begin
maxim:=0;
e:=1;
assign(fin,'transport.in');
reset(fin);
assign(fout,'transport.out');
rewrite(fout);
read(fin,n,k);
for I:=1 to n do begin
read(fin,x[i]);
if x[i]> maxim then maxim:=x[i];
end;
stanga:=maxim;
dreapta:=256000000;
while stanga<= dreapta do begin
mid:=stanga+(dreapta-stanga)div 2;
if aha(mid) then dreapta:=mid-1
else stanga:=mid+1;
end;
writeln(fout,stanga);
close(fin);
close(fout);
end.