Pagini recente » Cod sursa (job #2639879) | Cod sursa (job #3247550) | Cod sursa (job #570030) | Cod sursa (job #1878654) | Cod sursa (job #2374)
Cod sursa(job #2374)
const maxn=16000;oo=maxlongint div 4;
var t:Text;
V,S:Array[0..maxn]of longint;
i,n,k,lo,hi,juma,sol:longint;
function work(cap:longint):boolean;
var i,lo:longint;
begin
lo:=0;V[0]:=0;
for i:=1 to N do
begin
while (lo<i-1)and(S[i]-S[lo]>cap)do inc(lo);
V[i]:=1+v[lo];
end;
work:=V[n]<=K;
end;
begin
assign(t,'transport.in');reset(T);readln(t,n,k);
for i:=1 to N do begin readln(T,S[i]);if s[i]>lo then lo:=s[i];inc(S[i],S[i-1]);end;
close(t);sol:=oo;hi:=S[n];
while lo<=hi do
begin
juma:=(lo+hi)div 2;
if not work(juma) then lo:=juma+1 else
begin hi:=juma-1;if juma<sol then sol:=juma;end;
end;
assign(T,'transport.out');rewrite(T);writeln(t,sol);close(T);
end.