Pagini recente » Cod sursa (job #1274532) | Cod sursa (job #1511771) | Cod sursa (job #3280251) | Cod sursa (job #2554842) | Cod sursa (job #278458)
Cod sursa(job #278458)
var c,v,o,p:array[1..20000] of longint;
n,i,ind,ma,max,y,x,j,g,w:longint;
begin
assign(input,'ghiozdan.in'); reset(input);
assign(output,'ghiozdan.out'); rewrite(output);
readln(n,g);
for i:=1 to n do readln(v[i]);
ma:=-1;
for i:=1 to n do
begin
max:=-1;
for j:=1 to i-1 do
if (c[j]+v[i]<=g) then
begin
if max<c[j] then begin max:=c[j]; x:=o[j]; w:=j;end
else if (max=c[j])and(x>o[j]) then
begin
x:=o[j];w:=j;
end;
end;
if max=-1 then
begin
if v[i]<=g then
begin
o[i]:=1; c[i]:=v[i];p[i]:=0;
end
else c[i]:=-1;
end
else
begin
c[i]:=max+v[i];
o[i]:=x+1; p[i]:=w;
end;
if c[i]>ma then
begin
ma:=c[i]; y:=o[i]; ind:=i;
end
else if (c[i]=ma)and(y>o[i]) then begin y:=o[i];ind:=i;end;
end;
writeln(ma,' ',y);
i:=ind;
while i<>0 do
begin
writeln(v[i]);
i:=p[i];
end;
close(input); close(output);
end.