結果

問題 No.50 おもちゃ箱
ユーザー kohei2019kohei2019
提出日時 2021-06-02 21:49:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,805 ms / 5,000 ms
コード長 671 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 77,044 KB
最終ジャッジ日時 2024-04-27 14:47:30
合計ジャッジ時間 24,840 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
69,044 KB
testcase_01 AC 1,545 ms
76,364 KB
testcase_02 AC 59 ms
66,936 KB
testcase_03 AC 44 ms
54,000 KB
testcase_04 AC 43 ms
53,940 KB
testcase_05 AC 1,026 ms
76,480 KB
testcase_06 AC 173 ms
76,608 KB
testcase_07 AC 45 ms
54,852 KB
testcase_08 AC 45 ms
53,812 KB
testcase_09 AC 46 ms
54,524 KB
testcase_10 AC 44 ms
53,552 KB
testcase_11 AC 48 ms
60,536 KB
testcase_12 AC 44 ms
55,124 KB
testcase_13 AC 44 ms
53,532 KB
testcase_14 AC 60 ms
66,216 KB
testcase_15 AC 46 ms
53,568 KB
testcase_16 AC 60 ms
64,628 KB
testcase_17 AC 703 ms
76,588 KB
testcase_18 AC 120 ms
76,596 KB
testcase_19 AC 1,387 ms
76,428 KB
testcase_20 AC 67 ms
70,312 KB
testcase_21 AC 168 ms
76,440 KB
testcase_22 AC 992 ms
76,672 KB
testcase_23 AC 93 ms
76,496 KB
testcase_24 AC 44 ms
53,804 KB
testcase_25 AC 44 ms
54,592 KB
testcase_26 AC 69 ms
71,052 KB
testcase_27 AC 205 ms
76,424 KB
testcase_28 AC 909 ms
76,968 KB
testcase_29 AC 768 ms
76,624 KB
testcase_30 AC 827 ms
76,784 KB
testcase_31 AC 44 ms
54,180 KB
testcase_32 AC 1,805 ms
76,560 KB
testcase_33 AC 1,601 ms
77,044 KB
testcase_34 AC 1,242 ms
76,708 KB
testcase_35 AC 1,127 ms
76,916 KB
testcase_36 AC 1,367 ms
76,484 KB
testcase_37 AC 919 ms
77,004 KB
testcase_38 AC 989 ms
76,320 KB
testcase_39 AC 1,435 ms
76,660 KB
testcase_40 AC 1,546 ms
76,516 KB
testcase_41 AC 1,112 ms
76,408 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