結果

問題 No.50 おもちゃ箱
ユーザー convexineq
提出日時 2020-12-06 04:51:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 525 ms / 5,000 ms
コード長 483 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 75,928 KB
最終ジャッジ日時 2024-09-17 04:20:06
合計ジャッジ時間 10,745 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
*a, = map(int,input().split())
m = int(input())
*b, = map(int,input().split())

b.sort(reverse=True)
ans = INF = 100
from itertools import permutations
for lst in permutations(a):
    v = idx = 0
    for ai in lst:
        if v+ai > b[idx]:
            v = ai
            idx += 1
            if idx >= m or b[idx] < ai:
                idx = INF
        else:
            v += ai
        if idx >= ans: break
    ans = min(ans,idx)

print(ans+1 if ans!=INF else -1)
0