Cod sursa(job #480339)

Utilizator alin1303Bulai Alin alin1303 Data 27 august 2010 15:15:40
Problema Transport Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.64 kb
const max=256000000;
var f,g:text;
a:array[1..16000] of integer;
n,i,k:word;
k1,k2,mij:longint;
function ok(t:longint):boolean;
var i,u:integer;
c:longint;
begin
u:=1;
c:=0;
for i:=1 to n do
if c+a[i]>t then
begin
inc(u);
c:=a[i];
end
else
c:=c+a[i];
if u>k then
ok:=false
else ok:=true;
end;
begin
assign(f,'transpor.in');
reset(f);
assign(g,'transpor.out');
rewrite(g);
mij:=0;
read(f,n,k);
for i:=1 to n do
begin
read(f,a[i]);
if a[i]>mij then mij:=a[i];
end;
k1:=mij-1;
k2:=max;
while k2-k1>1 do
begin
mij:=(k1+k2) shr 1;
if ok(mij) then
k2:=mij
else k1:=mij;
end;
writeln(g,k1+1);
close(g);
close(f);
end.