結果

問題 No.50 おもちゃ箱
ユーザー norioc
提出日時 2025-03-19 05:13:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 511 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 82,172 KB
実行使用メモリ 76,776 KB
最終ジャッジ日時 2025-03-19 05:14:07
合計ジャッジ時間 17,881 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 RE * 1
other AC * 8 WA * 21 RE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import permutations

INF = 1 << 60
N = int(input())
A = list(map(int, input().split()))
M = int(input())
B = list(map(int, input().split()))


def put(xs) -> int:
    p = 0
    caps = [0] * N
    for x in xs:
        while p < N and caps[p]+x > B[p]:
            p += 1

        if p == N: return -1
        caps[p] += x

    return p+1


ans = INF
for ps in permutations(A):
    res = put(ps)
    if res == -1: continue
    ans = min(ans, res)

if ans == INF:
    print(-1)
else:
    print(ans)
0