# frozen_string_literal: true L = 3.times.map { gets.chomp } n = L[0].to_i L[2].split.map(&:to_i).sort.each_with_index do |w, i| n -= w if n.negative? p i exit end end