Pagini recente » Cod sursa (job #2460315) | Cod sursa (job #1739551) | Cod sursa (job #2116022) | Cod sursa (job #864400) | Cod sursa (job #47172)
Cod sursa(job #47172)
program ghiozdan;
var a:array[1..20000] of longint;
c,ant,c1:array[0..75000] of longint;
ap:array[0..200] of longint;
t,n,g,nmin,gmax,i,j,k,el:longint;
f:text;
begin
assign(f,'ghiozdan.in'); reset(f);
readln(f,n,g);
for i:=1 to n do readln(f,a[i]);
close(f);
for i:=1 to 200 do ap[i]:=0;
c[0]:=1;
for i:=1 to n do begin inc(ap[a[i]]); end;
for i:=1 to g do c[i]:=0;
ant[0]:=0;
for i:=1 to g do c1[i]:=c[i];
for i:=1 to 200 do
if ap[i]>0 then begin
for j:=0 to g do
if (c[j]>0) then begin
k:=1;
while (k<=ap[i]) and (j+k*i<=g) do begin
if (c[j+k*i]=0) or (c[j+k*i]>c[j]+k) then begin
c1[j+k*i]:=c[j]+k;
ant[j+k*i]:=j+(k-1)*i;
end;
k:=k+1;
end;
end;
for t:=1 to g do c[t]:=c1[t];
end;
i:=g;
while c[i]=0 do i:=i-1;
assign(f,'ghiozdan.out'); rewrite(f);
writeln(f,i,' ',c[i]-1);
while i>0 do begin
writeln(f,i-ant[i]);
i:=ant[i];
end;
close(f);
end.