Pagini recente » Cod sursa (job #2397484) | Cod sursa (job #3168845) | Cod sursa (job #1595625) | Cod sursa (job #2573503) | Cod sursa (job #482272)
Cod sursa(job #482272)
Program transport;
var v:array[1..16001]of integer;
n,k,i,max:longint;
function ok(x:longint):boolean;
var s,c,i:longint;
begin
s:=0;
c:=0;
i:=1;
while i<=n do begin
if v[i]>x then break;
if s+v[i]<=x then s:=s+v[i]
else begin
s:=v[i];
inc(c);
end;
inc(i);
end;
if i<=n then ok:=false
else begin
if c<k then ok:=true
else ok:=false;
end;
end;
function caut(a,b:longint):longint;
var mij:longint;
begin
while a<b do begin
mij:=(a+b)shr 1;
if ok(mij) then b:=mij
else a:=mij+1;
end;
caut:=a;
end;
begin
assign(input,'transport.in');
reset(input);
read(n,k);
max:=0;
for i:=1 to n do begin
read(v[i]);
if v[i]>max then max:=v[i];
end;
assign(output,'transport.out');
rewrite(output);
write(caut(max,n*max));
close(output);
end.