結果

問題 No.50 おもちゃ箱
コンテスト
ユーザー aaaaaaaaaa2230
提出日時 2022-01-01 20:41:19
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 591 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 192 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 80,896 KB
最終ジャッジ日時 2026-04-26 15:15:27
合計ジャッジ時間 3,824 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = sorted(list(map(int,input().split())),reverse=True)

dp = [0]*(1<<n)
dp[0] = 1
for i,b in enumerate(B,1):
    for bit in range(1<<n)[::-1]:
        if dp[bit] == 0:
            continue
        
        for mask in range(1<<n):
            if bit & mask:
                continue
            count = 0
            for j in range(n):
                if mask >> j & 1:
                    count += A[j]
            if count <= b:
                dp[bit^mask] = 1
    if dp[-1]:
        print(i)
        exit()
print(-1)
0