結果

問題 No.50 おもちゃ箱
ユーザー kohei2019kohei2019
提出日時 2021-06-02 21:49:02
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,838 ms / 5,000 ms
コード長 671 bytes
コンパイル時間 1,442 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 77,980 KB
最終ジャッジ日時 2023-08-09 20:15:03
合計ジャッジ時間 28,467 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
77,344 KB
testcase_01 AC 1,565 ms
77,464 KB
testcase_02 AC 100 ms
77,336 KB
testcase_03 AC 82 ms
71,580 KB
testcase_04 AC 83 ms
71,436 KB
testcase_05 AC 1,073 ms
77,332 KB
testcase_06 AC 204 ms
77,760 KB
testcase_07 AC 84 ms
71,872 KB
testcase_08 AC 84 ms
71,624 KB
testcase_09 AC 85 ms
71,796 KB
testcase_10 AC 85 ms
71,488 KB
testcase_11 AC 87 ms
75,908 KB
testcase_12 AC 86 ms
71,680 KB
testcase_13 AC 85 ms
71,616 KB
testcase_14 AC 102 ms
77,644 KB
testcase_15 AC 86 ms
71,604 KB
testcase_16 AC 98 ms
77,348 KB
testcase_17 AC 742 ms
77,296 KB
testcase_18 AC 153 ms
77,888 KB
testcase_19 AC 1,428 ms
77,492 KB
testcase_20 AC 109 ms
77,412 KB
testcase_21 AC 206 ms
77,500 KB
testcase_22 AC 1,043 ms
77,400 KB
testcase_23 AC 123 ms
77,344 KB
testcase_24 AC 83 ms
71,508 KB
testcase_25 AC 84 ms
71,764 KB
testcase_26 AC 112 ms
77,584 KB
testcase_27 AC 235 ms
77,356 KB
testcase_28 AC 956 ms
77,656 KB
testcase_29 AC 824 ms
77,464 KB
testcase_30 AC 867 ms
77,524 KB
testcase_31 AC 85 ms
71,704 KB
testcase_32 AC 1,838 ms
77,716 KB
testcase_33 AC 1,647 ms
77,748 KB
testcase_34 AC 1,289 ms
77,644 KB
testcase_35 AC 1,182 ms
77,752 KB
testcase_36 AC 1,394 ms
77,796 KB
testcase_37 AC 972 ms
77,980 KB
testcase_38 AC 1,052 ms
77,384 KB
testcase_39 AC 1,479 ms
77,664 KB
testcase_40 AC 1,566 ms
77,396 KB
testcase_41 AC 1,166 ms
77,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import copy
N = int(input())
lsA = list(map(int,input().split()))
M = int(input())
lsB = list(map(int,input().split()))
lsB.sort(reverse=True)

lsp = itertools.permutations(lsA)

cnt = float('INF')
for p in lsp:
    lsB1 = copy.copy(lsB)
    for i in range(N):
        f = False
        for j in range(M):
            if lsB1[j] >= p[i]:
                lsB1[j] -= p[i]
                f = True
                break
        if f == False:
            break
    if f:
        ii = 0
        for j in range(M):
            if lsB1[j] != lsB[j]:
                ii += 1
        cnt = min(ii,cnt)

if cnt == float('INF'):
    print(-1)
else:
    print(cnt)
0