Pagini recente » Cod sursa (job #755663) | Cod sursa (job #1423697) | Cod sursa (job #3229429) | Cod sursa (job #1037629) | Cod sursa (job #1453320)
var t:array[1..20000]of integer;
min,max,x,sum,n,i,k,tr,m:longint;
function ok(x:longint):boolean;
begin
sum:=0;
tr:=0;
i:=1;
while (i<=n)and(tr<k) do
begin
if sum+t[i]<=x then sum:=sum+t[i]
else
begin
tr:=tr+1;
sum:=t[i];
end;
i:=i+1;
end;
tr:=tr+1;
if tr<=k then ok:=true else ok:=false;
end;
begin
assign(input,'transport.in');
reset(input);
readln(n,k);
m:=0;
sum:=0;
for i:=1 to n do
begin
readln(t[i]);
sum:=sum+t[i];
if t[i]>m then m:=t[i];
end;
close(input);
max:=sum;
min:=max div k;
if min<m then min:=m;
while min<=max do
begin
x:=(min+max) div 2;
if ok(x) then max:=x-1
else min:=x+1;
end;
assign(output,'transport.out');
rewrite(output);
write(min);
close(output);
end.