結果

問題 No.50 おもちゃ箱
ユーザー koyopro
提出日時 2019-12-14 00:14:06
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 506 bytes
コンパイル時間 34 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-06-27 23:08:59
合計ジャッジ時間 6,713 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 1 TLE * 1 -- * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

N = gets.to_i
A = gets.split.map(&:to_i)
M = gets.to_i
B = gets.split.map(&:to_i).sort.reverse

ans = 100
A.permutation(N) do |list|
  box = B.dup
  index = 0
  ok = false
  list.each_with_index do |a, i|
    while index < box.size
      if box[index] >= a
        box[index] -= a
        ok = true if i == list.size - 1
        break
      else
        index += 1
      end
    end
  end
  ans = [index, ans].min if ok
end

if ans == 100
  puts '-1'
else
  puts ans + 1
end
0