Pagini recente » Cod sursa (job #1741987) | Cod sursa (job #1014765) | Cod sursa (job #630695) | Cod sursa (job #1405379) | Cod sursa (job #517374)
Cod sursa(job #517374)
const f='transport.in';g='transport.out';
nmax=16000;
var
a:array[1..nmax] of longint;
k,n,i:longint;
function rez(x:longint):longint;
var
nr,s,i:longint;
begin
nr:=1;s:=0;
for i:=1 to n do
if a[i]>x then begin rez:=k+1; exit; end
else
begin
s:=s+a[i];
if (s>x) then begin inc(nr);s:=a[i]; end;
end;
rez:=nr;
end;
function cauta(st,dr:longint):longint;
var
m:longint;
begin
m:=(st+dr) div 2;
if (st=dr) and (rez(m)<=k) then begin cauta:=st; exit;end;
if (st>dr) then begin cauta:=st;exit;end;
if (rez(m)<=k) then cauta:=cauta(st,m-1)
else cauta:=cauta(m+1,dr);
end;
begin
assign(input,f);reset(input);
assign(output,g);rewrite(output);
readln(n,k);
for i:=1 to n do
readln(a[i]);
a[n+1]:=a[n+1]+a[i];
write(cauta(1,a[n+1]));
close(input);close(output);
end.