class Yukicoder def initialize n, m = gets.chomp.split(' ').map(&:to_i) c = gets.chomp.split(' ').map(&:to_i).sort list = c.inject([0]){|e, s| e << e.last + s} puts list.rindex{|e| e <= m} end end Yukicoder.new