Pagini recente » Cod sursa (job #1562120) | Cod sursa (job #1608186) | Cod sursa (job #2386038) | Cod sursa (job #1688229) | Cod sursa (job #158182)
Cod sursa(job #158182)
program transport;
var a:array[1..16001]of integer;
s,ls,li,capacitate:longint;
n,k,i,j:integer;
f:text;
gasit:boolean;
procedure verif(cap:longint);
var kk:integer;
begin
s:=0; kk:=1; gasit:=true;
for i:=1 to n do
if s+a[i] > cap then begin
inc(kk);
s:=a[i];
if kk>k then begin
gasit:=false;
break;
end;
end
else inc(s,a[i]);
end;
begin
assign(f,'transport.in'); reset(f);
readln(f,n,k);
for i:=1 to n do readln(f,a[i]);
close(f);
assign(f,'transport.out'); rewrite(f);
{determin suma totala}
ls:=0;
for i:=1 to n do inc(ls,a[i]);
{det max}
li:=0;
for i:=1 to n do if a[i]>li then li:=a[i];
verif(li);
if gasit then writeln(f,li)
else begin
capacitate:=ls;
repeat
verif((li+ls)div 2);
if gasit then begin
capacitate:=(li + ls)div 2;
ls:=capacitate;
end
else li:=(li+ls)div 2;
until li+1=ls;
writeln(f,capacitate);
end;
close(f);
end.