eval"N,K,*A="+gets(p).split*?, N.downto(z=0){|i|A.combination(i){|a|n=a.sum n>K||n>z&&z=n}} p z