結果

問題 No.50 おもちゃ箱
コンテスト
ユーザー norioc
提出日時 2025-03-19 05:18:16
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 615 ms / 5,000 ms
コード長 533 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 243 ms
コンパイル使用メモリ 95,984 KB
実行使用メモリ 84,352 KB
最終ジャッジ日時 2026-07-07 06:26:03
合計ジャッジ時間 13,774 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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()))

B.sort(reverse=True)


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

        if p == M: 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