Pagini recente » Atasamentele paginii Clasament tema_vacanta_tiberiu_popoviciu | Cod sursa (job #2849996) | Cod sursa (job #2651144) | Cod sursa (job #2949169) | Cod sursa (job #301641)
Cod sursa(job #301641)
var v:array[1..15100] of longint;
i,x,k,n,s:longint;
f,g:text; ok:boolean;
procedure cauta(x:longint);
var i,j,con,dif:longint;
ok:boolean;
begin
dif:=x*k-s;
i:=1;
ok:=true;
while i<=n do begin
con:=0;
j:=i;
while (con<x) and (j<=n) do begin con:=con+v[j]; inc(j); end;
if con>x then begin dec(j); con:=con-v[j]; end;
dif:=dif-(x-con);
if dif<0 then begin break; ok:=false; end
else i:=j;
end;
if not ok then cauta(x+1)
else write(g,x);
end;
begin
assign(f,'transport.in'); reset(f);
assign(g,'transport.out'); rewrite(g);
read(f,n,k);
s:=0;
for i:=1 to n do begin
read(f,v[i]);
s:=s+v[i];
end;
if s mod k=0 then x:=s div k
else x:=(s div k)+1;
{i:=1;
dif:=x*k-s;
while ok do begin
con:=0;
j:=i;
while (con<x) and (j<=n) do begin con:=con+v[j]; inc(j); end;
if con>x then begin dec(j); con:=con-v[j]; end;
dif:=dif-(x-con);
if dif<0 then begin i:=1; inc(x); dif:=x*k-s; end
else i:=j;
if (dif>=0) and (i>=n) then ok:=false;
end;
write(g,x) }
cauta(x);
close(g);
end.