結果

問題 No.50 おもちゃ箱
ユーザー dangodango
提出日時 2023-07-09 16:22:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,104 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 77,824 KB
最終ジャッジ日時 2023-09-30 19:44:59
合計ジャッジ時間 11,027 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
76,556 KB
testcase_01 AC 205 ms
77,272 KB
testcase_02 AC 84 ms
75,660 KB
testcase_03 AC 75 ms
71,144 KB
testcase_04 AC 75 ms
71,292 KB
testcase_05 AC 78 ms
71,360 KB
testcase_06 AC 229 ms
77,440 KB
testcase_07 AC 75 ms
71,192 KB
testcase_08 AC 76 ms
71,032 KB
testcase_09 AC 76 ms
71,276 KB
testcase_10 AC 75 ms
71,200 KB
testcase_11 AC 77 ms
71,304 KB
testcase_12 AC 78 ms
71,272 KB
testcase_13 AC 76 ms
71,268 KB
testcase_14 AC 90 ms
76,300 KB
testcase_15 AC 75 ms
71,388 KB
testcase_16 AC 86 ms
76,224 KB
testcase_17 AC 562 ms
76,920 KB
testcase_18 AC 155 ms
77,388 KB
testcase_19 AC 316 ms
77,648 KB
testcase_20 AC 112 ms
76,920 KB
testcase_21 AC 116 ms
77,080 KB
testcase_22 AC 612 ms
77,312 KB
testcase_23 AC 134 ms
77,140 KB
testcase_24 AC 75 ms
71,384 KB
testcase_25 AC 76 ms
71,220 KB
testcase_26 AC 101 ms
76,820 KB
testcase_27 AC 90 ms
76,272 KB
testcase_28 AC 199 ms
77,640 KB
testcase_29 AC 177 ms
77,536 KB
testcase_30 AC 1,104 ms
77,232 KB
testcase_31 AC 75 ms
71,392 KB
testcase_32 AC 268 ms
77,156 KB
testcase_33 AC 682 ms
77,500 KB
testcase_34 AC 105 ms
77,472 KB
testcase_35 AC 425 ms
77,824 KB
testcase_36 AC 251 ms
77,200 KB
testcase_37 AC 216 ms
77,284 KB
testcase_38 AC 150 ms
77,212 KB
testcase_39 AC 185 ms
77,368 KB
testcase_40 AC 630 ms
77,196 KB
testcase_41 AC 75 ms
71,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def next_permutation(arr):
    i = len(arr) - 2
    while i >= 0 and arr[i] >= arr[i + 1]:
        i -= 1
    if i == -1:
        return False
    j = len(arr) - 1
    while arr[j] <= arr[i]:
        j -= 1
    arr[i], arr[j] = arr[j], arr[i]
    arr[i + 1:] = reversed(arr[i + 1:])
    return True
from itertools import permutations
n = int(input())
A = sorted(map(int, input().split()))
m = int(input()) + 1
B = list(reversed(sorted(map(int, input().split()))))
a = m
while True:
    T, i, j = B[:], 0, 0
    while i < n and j < m - 1:
        if T[j] >= A[i]:
            T[j] -= A[i]
            i += 1
        else:
            j += 1
    a = min(a, j + 1)
    if not next_permutation(A):
        break
print(a if a < m else -1)
0