Pagini recente » Cod sursa (job #2136915) | Cod sursa (job #2530952) | Cod sursa (job #814903) | Cod sursa (job #2706997) | Cod sursa (job #591582)
Cod sursa(job #591582)
var a:array[1..16000] of longint;
n,i,j,max,s,k,mijloc:longint;
f,g:text;
function ok(p:longint):boolean;
var i,t,sum:longint;
begin
t:=1;
sum:=a[1];
for i:=2 to n do
begin
if sum+a[i]<=p then sum:=sum+a[i]
else
begin
sum:=a[i];
inc(t);
end;
end;
if t<=k then ok:=true else ok:=false;
end;
begin
assign(f,'transport.in');
assign(g,'transport.out');
reset(f);
rewrite(g);
readln(f,n,k);
for i:=1 to n do
readln(f,a[i]);
max:=0;
s:=0;
for i:=1 to n do
begin
inc(s,a[i]);
if a[i]>max then max:=a[i];
end;
while max<>s do
begin
mijloc:=(max+s) div 2;
if ok(mijloc) then
s:=mijloc else
max:=mijloc+1;
end;
writeln(g,max);
close(g);
end.