結果

問題 No.50 おもちゃ箱
コンテスト
ユーザー H3PO4
提出日時 2020-04-22 10:15:20
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 629 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 415 ms
コンパイル使用メモリ 20,956 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2026-04-27 07:17:46
合計ジャッジ時間 7,745 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import itertools

N = int(input())
A = sorted(list(map(int, input().split())))
M = int(input())
B = sorted(list(map(int, input().split())), reverse=True)

for i, b in enumerate(B, 1):
    max_b = 0
    max_Ac = 0
    tmp = tuple([0] * len(A))
    it = itertools.product((0, 1), repeat=len(A))
    next(it)
    for t in it:
        A_c = tuple(itertools.compress(A, t))
        if max_b <= sum(A_c) <= b and max_Ac <= max(A_c):
            max_b = sum(A_c)
            max_Ac = max(A_c)
            tmp = t
    A = list(itertools.compress(A, (not x for x in tmp)))
    if not A:
        print(i)
        break
else:
    print(-1)
0