結果

問題 No.50 おもちゃ箱
ユーザー ytft
提出日時 2022-11-06 01:28:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,030 ms / 5,000 ms
コード長 435 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 76,492 KB
最終ジャッジ日時 2024-07-19 18:11:13
合計ジャッジ時間 29,899 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,itertools
input=lambda:sys.stdin.readline().rstrip()
N=int(input())
A=list(map(int,input().split()))
M=int(input())
B=sorted(list(map(int,input().split())))[::-1]
A=itertools.permutations(A)
ans=float('inf')
for i in A:
	temp=[0 for i in range(M)]
	for j in i:
		for k in range(M):
			if temp[k]+j<=B[k]:
				temp[k]+=j
				break
		else:
			break
	else:
		ans=min(ans,M-temp.count(0))
print(ans if ans!=float('inf') else -1)
0