Pagini recente » Cod sursa (job #2438574) | Cod sursa (job #870124) | Cod sursa (job #264255) | Cod sursa (job #322357) | Cod sursa (job #41385)
Cod sursa(job #41385)
var f,g:text;
s,m,n,k,i,p,x:longint;
a:array[1..16000]of integer;
e:boolean;
begin
assign(f,'transport.in');
reset(f);
readln(f,n,k);
for i:=1 to n do begin
read(f,a[i]);
s:=s+a[i];
if a[i]>m then m:=a[i];
end;
s:=s div k;
if s<m then s:=m;
e:=true;
while e do begin
m:=0;
p:=1;
for i:=1 to n do begin
x:=a[i];
if m+x>s then begin
p:=p+1;
m:=x;
end
else m:=m+x;
end;
e:=p>k;
if e then s:=s+p-k;
end;
assign(g,'transport.out');
rewrite(g);
write(g,s);
close(g);
end.