結果

問題 No.50 おもちゃ箱
ユーザー nebukuro09
提出日時 2016-10-02 19:58:46
言語 Python2
(2.7.18)
結果
AC  
実行時間 359 ms / 5,000 ms
コード長 432 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-06-25 21:49:32
合計ジャッジ時間 2,750 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

N = input()
A = map(int, raw_input().split())
M = input()
B = sorted(map(int, raw_input().split()))[::-1]

def rec(p, L):
    if p > N-1:
        return True
    for i in xrange(len(L)):
        if L[i] >= A[p]:
            L[i] -= A[p]
            if rec(p+1, L):
                return True
            L[i] += A[p]
    return False

for i in xrange(1, M+1):
    if rec(0, B[:i]):
        print i
        break
else:
    print -1
0