# yukicoder # No.5 数字のブロック # 数字が書かれているブロックはそれぞれ高さ1で幅はWiである。 # それらのブロックを高さ1,幅Lの大きな箱の中に入れる。 # 入力) # 16 大きな箱の幅を表すL(1≤L≤10000)L(1≤L≤10000) # 3 ブロックの数を表すN(1≤N≤10000)N(1≤N≤10000) # 10 5 7 各ブロックの幅を表すWi(1≤Wi≤L)Wi(1≤Wi≤L)が半角スペース区切り # 出力) # 2 big_w = gets.to_i #大きな箱の幅 num = gets.to_i #ブロックの数 n_w = gets.to_s #各ブロックの幅 n_w2 = n_w.split(" ") #スペース区切りの文字列から、空白を除いて配列に入れる if num <= n_w2.length n_w2.slice!(num..n_w2.length) #ブロックの個数を合わせる end n_w2.map!(&:to_i) #文字列から数値に変換 i = 0 ans = 0 n_w2.sort.each_with_index do |a, index| if i + a >= big_w ans = index break else i += a end end puts ans