Cod sursa(job #1150558)

Utilizator wollyFusy Wool wolly Data 23 martie 2014 12:01:07
Problema Transport Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.83 kb
type Tnum=array[1..17000] of longint;
var a,b:text;
	l,i,j,minG,maxSum,k,n:longint;
	t,s:Tnum;
	
function Max(f:longint):longint;
var m:longint;
begin
	Max:=0;
	for m:=1 to f do
	begin
		if s[m]>Max then Max:=s[m];
		{writeln(s[m]);}
	end;
	{writeln;}
	for m:=1 to f do
		s[m]:=0;
end;

procedure calc;
begin
	i:=1;
	j:=1;
	while (i<=k) and (j<=n) do
	begin
		if s[i]+t[j]<maxSum then
		begin
		s[i]:=s[i]+t[j];
		j:=j+1;
		end else i:=i+1;
	end;

end;

begin
assign(a,'transport.in');
reset(a);
assign(b,'transport.out');
rewrite(b);
read(a,n,k);
maxSum:=0;

for l:=1 to n do
begin
	read(a,t[l]);
	maxSum:=maxSum+t[l];
end;

i:=1;
j:=1;
Calc;

repeat
begin
	if j>n then
	begin
		maxSum:=Max(i);
		minG:=maxSum;
		Calc;
	end;
end;
until j<=n;

writeln(b,minG);

close(a);
close(b);
end.