結果
| 問題 | No.50 おもちゃ箱 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-06-02 21:49:02 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,803 ms / 5,000 ms | 
| コード長 | 671 bytes | 
| コンパイル時間 | 802 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 76,888 KB | 
| 最終ジャッジ日時 | 2024-11-15 17:35:41 | 
| 合計ジャッジ時間 | 25,255 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 38 | 
ソースコード
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)
            
            
            
        