@width = gets.chomp.to_i count = gets.chomp.to_i blocks = gets.chomp.split(" ").map(&:to_i).sort @current_width = 0 blocks.each_with_index do |b, i| @current_width += b if @current_width > @width puts i exit end end