結果

問題 No.50 おもちゃ箱
ユーザー rlangevin
提出日時 2023-09-01 12:05:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 163 ms / 5,000 ms
コード長 765 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2025-01-03 06:29:21
合計ジャッジ時間 4,943 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

inf = 10 ** 18
ans = inf

def dfs(L = [], now = 0):
    global ans
    if now == N:
        if len(L) > len(B):
            return
        temp = []
        for a in L:
            temp.append(a)
        temp.sort(reverse=True)
        flag = 1
        for i in range(len(temp)):
            if temp[i] > B[i]:
                flag = 0
                break
        if flag:
            ans = min(ans, len(temp))
        return
    for i in range(len(L)):
        L[i] += A[now]
        dfs(L, now + 1)
        L[i] -= A[now]
    L.append(A[now])
    dfs(L, now + 1)
    L.pop()
    return 

dfs()
print(ans) if ans != inf else print(-1)
0